验证部分不在蛋糕PHP工作

时间:2012-03-02 11:46:18

标签: php cakephp cakephp-1.3

这是行动网址

  http://localhost/carsdirectory/users/create_ad

create_ad.ctp(在此文件中我有选择字段,在此字段中我从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(controller)

 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');
  }
}

但验证不起作用此msg未显示请选择状态,如果我没有选择值,则插入null

我无法解决这个问题,所以请帮助我

提前感谢,vikas tyagi

1 个答案:

答案 0 :(得分:1)

看起来您正在尝试验证State.state_name字段,但您的表单输入为Location.state_id。确保它们匹配,然后重试。