-- asadkn <[EMAIL PROTECTED]> wrote
(on Tuesday, 15 April 2008, 02:18 PM -0700):
> Thanks. But I don't see how can it be applied to a full form.
> 
> For example, a form created like this:
> 
>               $form = new Zend_Form();
>               $form->setAction('/usr/login')
>                        ->setMethod('post')
>                        ->setDecorators(array(array('ViewScript', 
> array('class' => 'form
> element', 'viewScript' => 'index/form-test.phtml'))));
> 
>               // Create and configure username element:
>               $username = $form->createElement('text', 'username');
>  <snip>
> 
> Here, the viewScript is decorator is set to form-test.phtml, but I can't
> decorate the whole form using the view script? I will have hundreds of files
> if I have to create a view file for each element that needs more control
> (and allows designers to edit). 

You can loop over the form and render each item separately, or pull the
items out individually to render them:

    <? foreach ($this->form as $item): 
        // iteration occurs over elements, sub forms, and display groups ?>
        <?= $item?><? // render an invidual form item ?>
    <? endforeach ?>

    // or
    
    <form ....>
        some content
        <?= $this->form->foo ?>
    </form>

You can use the ViewScript on the form object so that you can do a more
complex form layout, and continue using standard decorators on the
elements. Or you can pull information from the individual elements in
order to build the HTML:

    <input type="text" name="username"
        value="<?= $this->form->username->getValue() ?>" />

etc.


> Matthew Weier O'Phinney-3 wrote:
> > 
> > -- 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/
> > 
> > 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Is-anyone-processing-Zend_Form-forms-manually-in-the-views--tp16629046p16710256.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
> 

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to