Nhu Trinh
Nhu Trinh

Reputation: 13956

Zend Form element default value empty

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 :(

Upvotes: 1

Views: 1847

Answers (2)

Megacier
Megacier

Reputation: 443

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!

Upvotes: 2

웃웃웃웃웃
웃웃웃웃웃

Reputation: 11984

Try this

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

Upvotes: 1

Related Questions