Owe*_*wen 3 zend-framework zend-form
我正在使用这个结构作为我的元素:
$freetext = $this->CreateElement('textarea', 'freetext')
->setLabel('Comments')
->setAttrib('class','input-textarea')
->setOptions(array('rows' => '2', 'cols'=>'30'))
->addValidator('StringLength', false, array(0,500))
->addFilter('HtmlEntities')
->addFilter('StripTags')
->setRequired(true);
Run Code Online (Sandbox Code Playgroud)
我想为此添加"allowEmpty"但无法找到正确的语法.我希望有类似的东西:
... ->addValidator('allowEmpty', false, true)
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
编辑:我已将setRequired()更改为true - 我希望允许空字符串作为require字段上的可接受值.
无论使用情况如何,如何将此选项添加到我的元素中?
- > setRequired(假);
如果您想允许空字符串并将空字符串保存到数据库,这就足够了.
如果您希望该字段是可选的,并且如果没有给出任何内容,则在数据库中保留空值,添加:
->addFilter(new Zend_Filter_Null)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7952 次 |
| 最近记录: |