1
votes

I have an Zend Form extended from Zend_Dojo_Form there are some input element added with $this->addElement('text','email'). In controller i prepopulate form field with

$myForm = new MyForm();
$this->view->myForm = $myForm;
$this->view->unsubscribeForm->email->setValue('abc@def');
$this->view->unsubscribeForm->email->setAttrib('whereismyvalue','missing');

And in view script, i use this to display

<?php echo $this->unsubscribeForm ?>

But when it is render the field value is missing

<input id="email" type="text" whereismyvalue="missing" value="" name="email">

even when I try

$this->view->unsubscribeForm->email->setAttrib('value','beep');

Nothing show up, and I dont know why :(

2
It works very well for me. Maybe you have a populate with email's value =''? - doydoy44
No, it always goes empty "", I can set any attribute i want but not value - James

2 Answers

2
votes

I'm pretty sure you check everytime if $form->isValid() before echo $this->form. That's a mistake. Make sure first that it is a post request and then check the form.

In fact $form->isValid($this->getRequest()->getPost();) reset every value in the form if they are not valid!

1
votes

Try this

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