Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zend framework - hidden element has no value even when specifying it

I create a hidden element that way:

$this->addElement('hidden', 'id', '1');

but what I get is this:

<input type="hidden" name="id" value="" id="id" />

I've also tried like this:

$this->addElement('hidden', 'id', array(
    'value' => 1
));

but it didn't work better.

What's wrong?

like image 732
Nicolas de Fontenay Avatar asked Apr 18 '11 10:04

Nicolas de Fontenay


2 Answers

You might be using

$form->populate($someData);

or

$form->isValid($someData);

somewhere in your code ;)

like image 125
Tomáš Fejfar Avatar answered Oct 04 '22 14:10

Tomáš Fejfar


I think you have to put in your form class:

public function populate(array $values) {
    parent::populate($values);
    $this->addElement('hidden', 'hidden');
    $el = $this->getElement('hidden');
    $el->setValue(1);

}
like image 20
Aigor Avatar answered Oct 04 '22 16:10

Aigor