Validation cakePHP验证错误未显示
因此,基本上我在我的用户控制器中有一个视图操作,用户可以在其中修改他的信息(用户名、名字、姓氏、电子邮件…)此表单发送到另一个更新操作,该操作执行保存操作,问题是,当我提交表单时,一个或多个字段不符合验证规则,它不会显示在每个字段下面,但数据不会保存和保存 $this->User->validationErrors 输出错误 我的更新操作(在view.ctp上提交表单后访问) view.ctp:Validation cakePHP验证错误未显示,validation,cakephp,Validation,Cakephp,因此,基本上我在我的用户控制器中有一个视图操作,用户可以在其中修改他的信息(用户名、名字、姓氏、电子邮件…)此表单发送到另一个更新操作,该操作执行保存操作,问题是,当我提交表单时,一个或多个字段不符合验证规则,它不会显示在每个字段下面,但数据不会保存和保存 $this->User->validationErrors 输出错误 我的更新操作(在view.ctp上提交表单后访问) view.ctp: <?php echo $this->Form->create('
<?php
echo $this->Form->create('User', array(
'inputDefaults' => array(
'div' => 'form-group',
'wrapInput' => false,
'class' => 'form-control'
),
'class' => 'well',
'url'=>array('controller'=>'users','action'=>'update'),
'id'=>'info-form'
));
?>
<fieldset>
<legend>Personal Information</legend>
<?php
echo $this->Form->input('id', array('value' => $userinfo['User']['id']));
echo $this->Form->input('User.username', array(
'label' => 'Username',
'value'=>$userinfo['User']['username']
));
?>
<td><?php echo $this->Form->error('username'); ?></td>
<?php
echo $this->Form->input('User.email', array(
'label' => 'E-mail',
'value'=>$userinfo['User']['email']
));
?>
<?php
echo $this->Form->input('User.fname', array(
'label' => 'First name',
'value'=>$userinfo['User']['fname']
));
?>
<?php
echo $this->Form->input('User.lname', array(
'label' => 'Last name',
'value'=>$userinfo['User']['lname']
));
?>
<?php
echo $this->Form->submit('Update', array(
'div' => 'form-group',
'class' => 'btn btn-success'
));
?>
</fieldset>
<?php echo $this->Form->end(); ?>
这是因为您在之后重定向-这将使其丢失验证警告。这是因为您在之后重定向-这将使其丢失验证警告。这是因为您在之后重定向-这将使其丢失验证警告。这是因为您在之后重定向-这将使其丢失验证警告。那么我该怎么做?@user3813360-这是一个完全不同的问题。请随时在StackOverflow上提问,我相信你会得到一些很好的答案。给这个人一枚奖章。我一直在拼命寻找这个解决方案。现在一切都很完美。非常感谢!那么我该怎么做呢?@user3813360-这是一个完全不同的问题。请随时在StackOverflow上提问,我相信你会得到一些很好的答案。给这个人一枚奖章。我一直在拼命寻找这个解决方案。现在一切都很完美。非常感谢!那么我该怎么做呢?@user3813360-这是一个完全不同的问题。请随时在StackOverflow上提问,我相信你会得到一些很好的答案。给这个人一枚奖章。我一直在拼命寻找这个解决方案。现在一切都很完美。非常感谢!那么我该怎么做呢?@user3813360-这是一个完全不同的问题。请随时在StackOverflow上提问,我相信你会得到一些很好的答案。给这个人一枚奖章。我一直在拼命寻找这个解决方案。现在一切都很完美。非常感谢!
function update() {
$this->autoRender = false;
$this->User->set($this->request->data);
if ($this->request->is('post')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('Information updated Successfuly.'), 'alert', array(
'plugin' => 'BoostCake',
'class' => 'alert-success'), 'success');
return $this->redirect('/users/view/' . $this->request->data['User']['id']);
} else {
// $errors = $this->User->validationErrors; var_dump($errors);die;
$this->Session->setFlash(__('An error occured'), 'alert', array(
'plugin' => 'BoostCake',
'class' => 'alert-danger'), 'danger');
return $this->redirect('/users/view/' . $this->request->data['User']['id']);
}
} else {
$this->Session->setFlash(__('Request was not of POST type.'), 'alert', array(
'plugin' => 'BoostCake',
'class' => 'alert-danger'), 'danger');
return $this->redirect('/users/index/');
}