4
我想補充的形式在產品頁面的附加信息請求。這是簡單的形式與名稱,國家,電子郵件和問題領域。簡單的形式,而不模型CakePHP中
我創辦這個tutorial,但我不喜歡的想法,只是針對小型化,我需要作出新的模型和控制器。
所以我products_controller.php
function sendemail(){
if(!empty($this->data)){
if($this->data['Product']['name'] && $this->data['Product']['country'] && $this->data['Product']['email'] && $this->data['Product']['question']){
// sending email
$this->Session->setFlash(__('Thanks, your qustion was send.', true), 'default', array('class' => 'message status'));
$this->redirect($this->referer());
} else {
// validation
$this->Session->setFlash(__('Fill all fiels', true), 'default', array('class' => 'message error'));
$this->redirect($this->referer());
}
} else {
$this->Session->setFlash(__('Error occurred', true), 'default', array('class' => 'message error'));
$this->redirect($this->referer());
}
}
在view.ctp
print $this->Form->create('', array('action' => 'sendemail'));
print $this->Form->input('name',array('label' => __('Name',true).':'));
print $this->Form->input('country',array('label' => __('Country',true).':'));
print $this->Form->input('email',array('label' => __('E-mail',true).':'));
print $this->Form->input('question',array('type' => 'textarea', 'label' => __('Your question',true).':'));
print $this->Form->end(__('Send', true));
,並添加功能sendemail
添加表單那麼,有沒有辦法如何正確地驗證表單如果某些字段不是重定向後填充此字段將被設置爲錯誤表單輸入?另外我怎樣才能將所有已填充的字段重新設置爲表單?
感謝您的幫助!