我的Form.php中有这段代码
$this->add(array(
'name' => 'unidades_andar',
'type' => 'number',
'attributes' => array(
'class' => 'form-control',
),
));这个在我的view.phtml里
<?php echo $this->formElement($form->get('unidades_andar')); ?>当我试图提交表格时,我有一个错误:
数组( unidades_andar => Array ( isEmpty =>值是必需的,不能为空))
我已经尝试设置“必需的=>假”。
如果我把类型改为文本而不是数字,它就能工作。
但是为什么我不能使用类型号呢?它似乎总是需要的..。
发布于 2015-09-15 12:24:40
如果您查看zend-framework/zend-form/src/Element/Number.php的源,可以看到默认情况下将此字段设置为必需的。
/**
* Provide default input rules for this element
*
* Attaches a number validator, as well as a greater than and less than validators
*
* @return array
*/
public function getInputSpecification()
{
return array(
'name' => $this->getName(),
'required' => true,
'filters' => array(
array('name' => 'Zend\Filter\StringTrim')
),
'validators' => $this->getValidators(),
);
}所以你需要这样做
public function getInputFilterSpecification()
{
return [
[
"name"=>"unidades_andar",
'required' => false,
'allow_empty' => true, // this will allow submitting empty values like ''
],
];
}https://stackoverflow.com/questions/32585600
复制相似问题