'正在尝试在表单中使用 setBelongsTo,但 Zend 不验证值并且不 setDefaults 该字段。在谷歌上搜索过,什么也没找到。任何想法?
形式:
$this->setName('form_tecnicos')
->setAttrib('onSubmit',"return validarForm()");
$elementos['nome'] = new Zend_Form_Element_Text('nome');
$elementos['nome']->setLabel('Nome')
->setRequired(true)
->setAttrib('maxlength','150');
$elementos['telefone0'] = new Zend_Form_Element_Text('0');
$elementos['telefone0']->setLabel('Telefones')
->setRequired(true)
->setAttribs(array('mascara'=>'tel','maxlength'=>14))
->setBelongsTo('telefones');
$elementos['telefone1'] = new Zend_Form_Element_Text('1');
$elementos['telefone1']->setLabel('Telefones')
->setRequired(true)
->setAttribs(array('mascara'=>'tel','maxlength'=>14))
->setBelongsTo('telefones');
$elementos['submit'] = new Zend_Form_Element_Submit('Entrar');
$elementos['submit']->setLabel('Entrar');
$this->addElements($elementos);
$filters = array('StringTrim');
$this->setElementFilters($filters);
$this->setElementDecorators(array(
'viewHelper',
'Errors',
array(array('data'=>'HtmlTag'), array('tag' => 'dd')),
array('Label',array('tag'=>'dt')),
array(array('row'=>'HtmlTag'),array('tag'=>'div','class'=>'grid_2'))
));
$remover_label = array('submit');
foreach($remover_label as $elementos)
$this->$elementos->removeDecorator('label');
控制器
$form = new Application_Form_Tecnicos();
$this->view->form = $form;
if($this->getRequest()->isPost()):
$dados = $this->getRequest()->getPost();
if($form->isValid($dados)):
//
else:
$form->setDefaults($dados);
endif;
endif;
打印_r($dados)
Array ( [nome] => [telefones] => Array ( [0] => (11) 1111-111 ) [Entrar] => Entrar )
我坚持下去