返回在我的模型Zend的格式錯誤的消息沒有從功能
$form = new \Zend_Form();
$form->addElement('text', 'name', array(
'validators' => array(
array('NotEmpty', true),
array("stringLength", true, array(1,40))
),
'required' => true,
'label' => "Name",
));
return $form;
在我的控制器,叫上面的模型功能
if($form->isValid($_POST)) {
....
} else {
$form = Product::getForm();
print_r($form->getErrors());
print_r($form->getErrorMessages());
print_r($form->getMessages());
}
我使用Zend框架。
這裏在名稱字段的形式中,字符串超過40個字符需要顯示錯誤消息。
我試着用getErrors()
和getErrorMessages()
得到錯誤。但是這些功能都沒有給我錯誤。 它在打印這些函數時返回一個空數組。
請幫我解決這個問題......直到你叫isValid()
的形式,像這樣
$form = Product::getForm();
if(!$form->isValid($_POST))
{
print_r($form->getErrors());
print_r($form->getErrorMessages());
print_r($form->getMessages());
}
沒問題,值得一提的是它很低。 – 2012-08-07 11:07:41