使单个表单字段CakePHP无效

时间:2017-08-03 15:43:55

标签: cakephp-3.0

我创建了一个无模型表单:

$address = new AddressForm();

  if ($this->request->is('post')) {

$address->setErrors(["line1" => ["_custom" => 'Inavlid field']]);
      if ($address->execute($this->request->getData())) {
          $this->Flash->success('Valid address');
      } else {
          $this->Flash->error('There was a problem submitting your form.');
      }
    }

$this->set(compact('address'));

如文档Invalidating Individual Form Fields from Controller中所述,我现在想要使控制器中的字段无效,但执行方法仍然标记为有效:

<?php
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
header('Content-Type: text/html; charset=UTF-8');
?>

我正在错误地使用setErrors方法吗?

1 个答案:

答案 0 :(得分:0)

只需在execute()调用下移动setErrors()行,它就会重置错误......