2014-01-29 67 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