Zend 自动在它生成的表单元素周围添加标签。如何将这些标签作为参数删除到 addElement 函数。
我尝试更改 disableLoadDefaultDecorators 标志,但是该元素根本不呈现。
例如: $searchForm->addElement('text', 'searchText', array('class'=>'onClickClear', 'disableLoadDefaultDecorators' => true));
Zend 自动在它生成的表单元素周围添加标签。如何将这些标签作为参数删除到 addElement 函数。
我尝试更改 disableLoadDefaultDecorators 标志,但是该元素根本不呈现。
例如: $searchForm->addElement('text', 'searchText', array('class'=>'onClickClear', 'disableLoadDefaultDecorators' => true));
您可以通过传递要加载的装饰器数组来覆盖 createElement / addElement 中的默认装饰器。
“ViewHelper”装饰器通常呈现表单元素本身,“错误”用于验证器问题,“标签”用于表单元素通常很方便。
$searchForm->addElement('text', 'searchText', array(
'class'=>'onClickClear',
'decorators'=>Array(
'ViewHelper',
'Error',
array('Label', array('tag' => 'div')),
),
));
另一种方法是在初始化表单后立即调用 setElementDecorators(),它为所有后续元素设置默认装饰器。我将下面的代码用于非常简单的(一个或两个字段表单),我只想显示在一行上并且不需要大量验证:
$form = new Zend_Form();
$form->setElementDecorators( array( 'ViewHelper', 'Label' ) );
我认为这将有助于删除 HtmlTag 装饰器:
$element = $searchForm->createElement('text', 'searchText', array('class'=>'onClickClear'));
$element->removeDecorator('HtmlTag');
$searchForm->addElement($element);