post 请求后的第一个输入块。蛋糕PHP

the first input block after a post request. cakephp

我在使用 cakephp 中的表单时遇到了一点问题。当视图第一次呈现时,我可以在所有输入中引入信息,但在提交后,如果第一个输入块的验证失败,我无法在其中引入更多信息,但在其余部分我可以。这是视图:

<?php
echo $this->Form->create('User');
echo $this->Form->input('phone');
echo $this->Form->input('complete_name');
echo $this->Form->input('adress');
echo $this->Form->input('state');
echo $this->Form->input('city');
echo $this->Form->input('zip_code');
echo $this->Form->button('Save', array('name' =>'save'));
echo $this->Form->end();
?>

在控制器中:

public function user_info(){
if($this->request->is('post'))
{
    if($this->User->save($this->request->data))
    {
      $this->redirect(array('controller' => 'users', 'action' => 'user_store'));
    }
    else
    {
     $this->Session->setFlash(__('problem saving'), 'flash_bad');
    }
}

模型验证:

public $validate = array(
  'complete_name' => array(
     'notempty' => array(
       'rule' => array('custom','/^[a-z A-ZáéíóúÁÉÍÓÚñÑäëïöüÄËÏÖÜ]{5,}$/i'),
       'message' => 'fail the name'
     ),
     'maxlength' => array(
        'rule' => array('maxlength', 45)
     )
    ),      

  'adress' => array(
      'notempty' => array(
        'rule' => array('notempty'),
        'message' => 'fail adress',
        ),
      'maxlength' => array(
        'rule' => array('maxlength', 60),
        ),
      'minlength' => array(
        'rule' => array('minlength', 10),
        'message' => 'fail adress'
        )
    ),

  'state' => array(
      'notempty' => array(
        'rule' => array('custom', '/^[a-z A-ZáéíóúÁÉÍÓÚñÑäëïöüÄËÏÖÜ]{5,}$/i'),
        'message' => 'fail state'
        ),
      'maxlength' => array(
        'rule' => array('maxlength', 30)
        )
    ),

  'city' => array(
     'notempty' => array(
       'rule' => array('custom', '/^[a-z A-ZáéíóúÁÉÍÓÚñÑäëïöüÄËÏÖÜ]{5,}$/i'),
       'message' => 'fail city'
        ),
     'maxlength' => array(
        'rule' => array('maxlength', 30)
        )
    ),

  'zip_code' => array(
     'notempty' => array(
        'rule' => '/^[1-9]{4,4}$/i',
        'message' => 'fail zip code'
        )
    )
);

当验证失败时,我可以在视图中看到消息,会话也会闪烁,我可以编辑除 phone 之外的所有内容。如果我像这样在视图代码中交换行:

<?php
echo $this->Form->create('User');
echo $this->Form->input('complete_name'); // change position with phone
echo $this->Form->input('phone');
echo $this->Form->input('adress');
echo $this->Form->input('state');
echo $this->Form->input('city');
echo $this->Form->input('zip_code');
echo $this->Form->button('Save', array('name' =>'save'));
echo $this->Form->end();
?>

那我就不能编辑了complete_name。有人知道发生了什么吗?

根据您的描述,我认为 css 或 jQuery 正在放置一个 div 扩展到该输入以防止您对其进行编辑,也许 div使用 error class 甚至在第一个输入上进行填充都可能导致问题。无论如何,请使用 Firefox 中的 Firebug 等开发人员工具进行调查。您将能够看到这是否是正在发生的事情。