Zend Form元素的默认值为空

时间:2014-06-12 03:45:18

标签: php zend-framework zend-form

我有一个从Zend_Dojo_Form扩展的Zend表单,有一些输入元素添加了$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');

什么都没有出现,我不知道为什么:(

2 个答案:

答案 0 :(得分:2)

我非常确定您在$form->isValid()之前echo $this->form检查每次。那是个错误。首先确保它是发布请求,然后检查表单

实际上$form->isValid($this->getRequest()->getPost();)重置表单中的每个值,如果它们无效!

答案 1 :(得分:1)

试试这个

$this->view->myForm->getElement('email')->setValue('abc@def');
$this->view->myForm->getElement('email')->setAttrib('value','beep');