サイト用の簡単な連絡先フォームを作成しています。
私のモデルには次のものがあります。
class Contact extends AppModel {
public $useTable = false;
public $validate = array(
'name' => array(
'rule' => 'notEmpty',
'message' => 'Field name must be not empty'
),
'email' => 'email',
'message' => array(
'rule' => 'notEmpty',
'message' => 'Field message must be not empty'
)
);
}
コントローラ:
class ContactsController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
}
public function send() {
$this->Contact->set($this->request->data);
if ($this->Contact->validates()) {
//sending mail logic
};
} else {
// didn't validate logic
$errors = $this->Contact->validationErrors;
}
}
}
}
そして index.ctp ビューには次のものがあります。
echo $this->Form->create('Contact', array('action' => 'send'));
echo $this->Form->input('name', array('label' => 'Your name:'));
echo $this->Form->input('email', array('label' => 'Your e-mail:'));
echo $this->Form->input('message', array('rows' => '6', 'label' => 'Your message:'));
echo $this->Form->end('Send button');
echo $this->Session->flash();
したがって、コントローラーからの検証データを使用しているため、$errors を Session->flash に渡す際に問題が発生します。それを行う適切な方法は何ですか?コントローラーで「send」メソッドの追加ビューを作成したくありません。