pia-sophie
pia-sophie

Reputation: 505

using setValue in Zend-Form

I try to pass a value to an Zend-Form element. It shall be filled when the formclass is instantiated. Perhaps it is even the wrong idea?

What I gonna do:

I want to give a value to my formclass via my controller addAction:

$form = new PadForm(NULL, $test->UnitPartID);

Here is the constructor of my form class:

 public function __construct($name = null, $unitpartid)

Now I thought it must be easy to give the value to an element:

add.phtml

$UnitPartID= $form->get('UnitPartID');
$UnitPartID->setAttribute('class', 'form-control');
$UnitPartID->setAttribute('placeholder', 'UnitPartID');

$UnitPartID->setValue($this->unitpartid);

Unfortunately the form element doesn't get the value.

Where is the error? I think I'm quite close to the solution?? Any help appreciated.

Upvotes: 1

Views: 1719

Answers (1)

pia-sophie
pia-sophie

Reputation: 505

It's a bit of a shame, because it is so easy in the end. But for beginners in Zend, it is sometimes hard to understand, where to do things properly. So I want to post the solution for others who have the same issues.

In my controller addaction I gave the form field a value, after instantiating the Form class.

$form->get('Formfield')->setValue(some variable);

I had the hole topic, because I was searching for a possibility to do it in the view. There I could give a value of course, but I couldn't fetch a variable. If somebody has still a suggestion for this possibility, please post. I answer my question because I now have one working solution.

Upvotes: 1

Related Questions