我有以下 ZF 表单元素。
$this->addElement('text', 'price', array(
'required' => true,
'label' => 'Price:',
'attribs' => array(
'title' => 'Please enter the value of your artwork'),
'filters' => array('Currency'),
'validators' => array(
array('NotEmpty', true, array(
'messages' => array(
Zend_Validate_NotEmpty::IS_EMPTY =>
"You must enter your artworks price"))),
array('Float', true, array(
'messages' => array(
Zend_Validate_Float::INVALID =>
"You must enter a valid price",
Zend_Validate_Float::NOT_FLOAT =>
"You must enter a valid price"))),
array('GreaterThan', true, array(
'min' => 0.99,
'messages' => array(
Zend_Validate_GreaterThan::NOT_GREATER =>
"You must enter a value of £1.00 or more"))))
));
最后一个验证器是 Zend_Validate_GreaterThan ,它设置了一个错误消息,我的问题是当这个验证器失败时错误消息没有显示在表单上。我得到的只是一个空的无序列表!!
<ul>
<li></li>
</ul>
当我检查 zend_form 输出的消息时,我得到了错误和消息。
array(1) {
["price"]=>
array(1) {
["notGreaterThan"]=>
string(39) "You must enter a value of £1.00 or more"
}
}
有谁知道为什么没有在表单上呈现消息?
提前谢谢了
加里
编辑
我使用的唯一装饰器是在我拥有的表单上呈现表单的视图脚本。
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'forms/add-item.phtml'))
));
和视图本身。
$attribFilterObj = new Freedom_Zend_Filter_HtmlAttribs();
$attribs = $attribFilterObj->filter($this->element->getAttribs());
?>
<form <?php echo $attribs; ?>>
<dl>
<?php echo $this->element->ArtworkTitle->title->render(); ?>
<?php echo $this->element->ArtworkDescription->description->render(); ?>
<?php echo $this->element->price->render(); ?>
<?php echo $this->element->Genres->render(); ?>
<?php echo $this->element->image->render(); ?>
<?php echo $this->element->add->render(); ?>
</dl>
</form>
编辑
var_dump 的输出如下
array(5) {
["Zend_Form_Decorator_ViewHelper"]=>
object(Zend_Form_Decorator_ViewHelper)#157 (6) {
["_buttonTypes":protected]=>
array(3) {
[0]=>
string(24) "Zend_Form_Element_Button"
[1]=>
string(23) "Zend_Form_Element_Reset"
[2]=>
string(24) "Zend_Form_Element_Submit"
}
["_helper":protected]=>
NULL
["_placement":protected]=>
string(6) "APPEND"
["_element":protected]=>
NULL
["_options":protected]=>
array(0) {
}
["_separator":protected]=>
string(2) "
"
}
["Zend_Form_Decorator_Errors"]=>
object(Zend_Form_Decorator_Errors)#158 (4) {
["_placement":protected]=>
string(6) "APPEND"
["_element":protected]=>
NULL
["_options":protected]=>
array(0) {
}
["_separator":protected]=>
string(2) "
"
}
["Zend_Form_Decorator_Description"]=>
object(Zend_Form_Decorator_Description)#159 (6) {
["_escape":protected]=>
NULL
["_placement":protected]=>
string(6) "APPEND"
["_tag":protected]=>
NULL
["_element":protected]=>
NULL
["_options":protected]=>
array(2) {
["tag"]=>
string(1) "p"
["class"]=>
string(11) "description"
}
["_separator":protected]=>
string(2) "
"
}
["Zend_Form_Decorator_HtmlTag"]=>
object(Zend_Form_Decorator_HtmlTag)#160 (7) {
["_encoding":protected]=>
NULL
["_placement":protected]=>
NULL
["_tag":protected]=>
NULL
["_tagFilter":protected]=>
NULL
["_element":protected]=>
NULL
["_options":protected]=>
array(2) {
["tag"]=>
string(2) "dd"
["id"]=>
array(1) {
["callback"]=>
array(2) {
[0]=>
string(22) "Zend_Form_Element_Text"
[1]=>
string(16) "resolveElementId"
}
}
}
["_separator":protected]=>
string(2) "
"
}
["Zend_Form_Decorator_Label"]=>
object(Zend_Form_Decorator_Label)#161 (6) {
["_placement":protected]=>
string(7) "PREPEND"
["_tag":protected]=>
NULL
["_tagClass":protected]=>
NULL
["_element":protected]=>
NULL
["_options":protected]=>
array(1) {
["tag"]=>
string(2) "dt"
}
["_separator":protected]=>
string(2) "
"
}
}