我有一个从Zend_Dojo_Form
扩展的Zend Form,有一些输入元素添加了$this->addElement('text','email')
。在控制器i用
$myForm = new MyForm();
$this->view->myForm = $myForm;
$this->view->unsubscribeForm->email->setValue('abc@def');
$this->view->unsubscribeForm->email->setAttrib('whereismyvalue','missing');
在视图脚本中,我用它来显示
<?php echo $this->unsubscribeForm ?>
但是当它被渲染时,字段值丢失了
<input id="email" type="text" whereismyvalue="missing" value="" name="email">
即使我尝试
$this->view->unsubscribeForm->email->setAttrib('value','beep');
没有显示,我不知道为什么:
我很确定你每次检查如果$form->isValid()
在echo $this->form
之前。这是一个错误。首先确保它是一个post请求,然后检查表单。
事实上,$form->isValid($this->getRequest()->getPost();)
重置表单中所有无效的值!
试试这个
$this->view->myForm->getElement('email')->setValue('abc@def');
$this->view->myForm->getElement('email')->setAttrib('value','beep');