[英]validation part not working in cake php
这是动作网址
http://localhost/carsdirectory/users/create_ad
create_ad.ctp(在此文件中,我具有select字段,在此字段中,我从state_name字段表名称状态中提取数据)
<label class="ls-details-label">State</label>
<div class="ls-details-box">
<?php
foreach ($states as $state)
{
$state_new[$state['State']['id']]=$state['State']['state_name'];
}
echo $this->Form->input('Location.state_id',array('label'=>false,'options'=>$state_new,'empty'=>' Select ','class'=>'styledselect_form_1'));
?>
</div>
state.php(模型)
<?php
class State extends AppModel
{
var $name = 'State';
var $validate = array(
'state_name' => array(
'rule' => 'notEmpty',
'message' => 'Please select a state')
);
}
?>
users_controller.php(控制器)
public function create_ad()
{
$this->loadModel('Location');
if($this->Location->saveAll($this->data['Location']))
{
$this->data['Car']['location_id'] = $this->Location->id;
}
else
{
$this->Session->setFlash('Detail could not be saved in Cars Controller');
}
}
但是验证不起作用,此消息未显示。请选择一个状态,如果im未选择值,则插入null
我无法解决该问题,所以请帮助我
在此先感谢,vikas柳枝
看起来您正在尝试验证State.state_name
字段,但是表单的输入是Location.state_id
。 确保它们匹配,然后重试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.