-1
我在寫一個聯繫表單並想添加一些簡單的驗證例程。該頁面的操作是這樣的:CakePHP沒有檢查表單驗證
public function contact() {
$this->loadModel('Contact');
$this->set('pageTitle', 'Contact me');
}
和Contact
模式是這樣的:
<?php
class Contact extends AppModel {
public $useTable = false;
public $validate = array(
'name' => array(
'between' => array(
'rule' => array('between', 1, 60),
'message' => 'Between 1 and 60 characters in length'
)
),
'email' => array(
'kosher' => array(
'rule' => 'email',
'message' => 'Please make sure your email is entered correctly'
),
),
'message' => array(
'between' => array(
'rule' => array('between', 1, 65000),
'message' => 'Between 1 and 65000 characters in length'
)
)
);
}
,最後我的看法頁:
<?php echo $this->Form->create('Contact'); ?>
<?php echo $this->Form->input('name'); ?>
<?php echo $this->Form->input('email'); ?>
<?php echo $this->Form->input('message', array('type' => 'textarea')); ?>
<?php echo $this->Form->end(array('label' => 'Send', 'class' => 'btn btn-primary')); ?>
然而,當我用不正確的值提交表單時,不會調用驗證例程,也不會出現錯誤消息所示。
我如何獲得Cake來驗證表單?