Zend表单元素默认值为空


Zend Form element default value empty

我有一个从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');