2
我有問題..我試圖填充表單,然後單擊提交按鈕,然後它顯示錶單錯誤,但所有這些文本框字段去空白空可以顯示錶單錯誤。我希望它在驗證之前變成同樣的值。就像我不想在驗證後清除/清空值。CakePHP驗證後,所有表單域變空表格錯誤
我做了這樣的事情:(鑑於)
<div class="regform">
<div id="formleft">First Name<asterix>*</asterix></div>
<div id="formright"><?php echo $this->Form->input('First Name', array(
'name' => 'firstname',
'label'=> false
)); ?></div>
<div id="formerror"><?php echo $this->Form->error('Customer.firstname'); ?></div>
</div>
(模型):
'firstname' => array(
'firstname_cant_be_empty' => array(
'rule' => 'notEmpty',
'message' => 'First Name must be filled.'
),
'firstname_must_be_alphabet' => array(
'rule' => '/^[a-z]{3,}$/i',
'message' => 'First Name is only letters. No numbers, Dotted, etc.'
)
)
(在控制器):
if ($this->request->is('Post')) {
if ($this->Customer->save($this->request->data) && $this->Customer->validates()) {
//debug($this->request->data);
$this->Session->setFlash('good!');
//$this->redirect('/');
} else {
$this->Session->setFlash('Fill up form now!');
$this->data = $this->request->data;
}
}
我不認爲你需要$ this-> Customer-> validates(),因爲它已經在save方法中做了。 – jimiyash 2012-04-21 19:04:01