-- asadkn <[EMAIL PROTECTED]> wrote
(on Friday, 11 April 2008, 02:25 PM -0700):
> I want to keep the forms separated in the views and thus would like to parse
> generated forms in views. Instead of relying on Zend_Form decorators
> generated HTML, I would like to do it all manually. It gets extremely messy
> when I have to use decorators with few of my HTML-rich forms.
Please check out the ViewScript decorator in the documentation; this is
probably the best fit for your needs. Set your form to use this
decorator, and then you can customize the output of your form as you see
fit. You can find that documentation on the following manual page:
http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.viewScript
> Perhaps I want to create <div> and other such HTML elements myself, but use
> Zend_Form's decorators to create the input, select, etc. (and obviously have
> them filled when editing). That still should save me from writing lot of
> repeated code.
>
> In views, I wish if something like this was possible: (where $this->form is
> a form created using Zend_Form in the controller)
>
> <div> - <?php echo $this->form->getElement('username')->render(); ?></div>
In your view script (used with the ViewScript decorator, as recomended
above), you could do exactly that, only easier:
<div><?php echo $this->form->username ?></div>
> As I see it, each element's data is protected and thus cannot be accessed
> from outside. Maybe I should try sub-classing Zend_Form each time but that
> still will require me to spend a lot of time to figure out how to do it
> right.
Not true -- there are accessors for every member stored in the form
elements, and most metadata is actually directly accessible as virtual
members using overloading. Please read up on the documentation:
http://framework.zend.com/manual/en/zend.form.elements.html#zend.form.elements.metadata
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/