> Yes, add a setter method for attaching the model to the form and then do
> this in the controller. The form will then have access to the model to
> retrieve any data it needs.
>
> You can also populate the element directly in your controller by retrieving
> it from the form and manipulating it e.g. $form->getElement('some
> element')->setMultiOptions(some array).
>
>>so what is the use of populate and setDefaults functions?
>
> both are used to set the values of the elements, there no difference between
> the two.
>

Ok, this is the type of explanation I am looking for. Now I understand
how to manipulate form from controller. I guess the later method is
suitable for me on what I am trying to do.

Now I understand why we were not able to understand each other. It is
because I was looking for a way to populate the form elements.
Initially I thought of creating the variable in form class and getter,
setter methods but when I dug around a bit, I found the explanation in
the documentation
http://framework.zend.com/manual/en/zend.form.forms.html#zend.form.forms.elements.values
which knocked me off from the right track.

>From the documentation, what I understood is $form->populate($data) is
the way to send the data to the form for manipulation (not setting the
value in already populated element).  I thought that it is part of the
ZF's behind the scene magic where form knows what data have been
passed by the controller.

Anyway it is nobody's fault but the documentation is somewhat
misleading. If you think of it naturally, populate is synonymous with
populating database tables (not selecting an particular item).

Now its all clear and I have tried the second method and it works but
with a minor problem which I still don't understand. I will be posting
that problem in next thread since this part is solved already.

Thank you both for being very patient with me.

Regards


-- 
=======================
Registered Linux User #460714
Currently Using Fedora 8, 10
=======================

Reply via email to