2014-01-29 68 views
0

我有以下形式:CakePHP的驗證工作不

<?php echo $this->Html->image('itemdefault.gif',array('class'=>'image1')); ?> 
    <?php echo $this->form->input('quantity',array('class'=>'input')); ?><br> 
    <?php echo $this->form->input('SpecialInstructions', array('type'=>'select','style'=>'font-size:13pt;width:120px;','options'=>$spec_ins)); ?><br> 
    <?php echo $this->form->input('Ingredients',array('class'=>'input'));  ?><br> 
    <?php echo $this->form->end('Save',array('class'=>'button1'));  

,這是在模型驗證:

var $validate=array 
(
    'quantity'=>array 
    (
     'numeric'=>array('rule'=>'numeric','required'=>true,'message'=>'Enter numbers only'), 
     'qty_must_not_be_blank'=>array('rule'=>'notEmpty','message'=>'Quantity cannot be left blank') 
    ), 
    'Ingredients'=>array 
    (
     'body_must-not_be_blank'=>array('rule'=>'notEmpty','message'=>'Body must not be blank') 
    ) 
); 

但沒有驗證的工作。是因爲這些字段不存在於我的數據庫中?

+0

您如何知道驗證無效?你是怎麼測試的? –

+0

在您的問題中加入更多詳細信息以進行澄清 – Anubhav

回答

0
echo $this->Form->create(); 

從代碼中缺失。嘗試將其包含在代碼的開頭

+0

它在我的代碼中存在...我只是忘記將其粘貼到我的代碼片段中。 – TheIntern

+0

好的,你的數據保存是否正確?你能否也提供控制器代碼? – raumus