Re: [fw-general] Is anyone processing Zend_Form forms manually in the views?
Ok, I get it now. So basically, ViewScript decorator is un-necessary in my case; since we're taking the data and parsing it manually in a custom view script. When this is how the form is created: $form = new Zend_Form(); $form->setAction('/usr/login') ->setMethod('post'); $this->view->form =$form; $this->render('test'); test.phtml can then contain: (as you mentioned) echo $this->form->foo; echo $this->form->foo->getName(); // all good! ahh.. Now only if I ever took a look at the __get() method's implementation in Zend_Form! Thanks a lot. I just added that for future reference - might be useful for someone who needs to do something similar. Matthew Weier O'Phinney-3 wrote: > > -- 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'); >> >> >> 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: > > form as $item): > // iteration occurs over elements, sub forms, and display groups > ?> > > > > // or > > > some content > form->foo ?> > > > 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: > > value="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 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) >> >> >> >> - form->getElement('username')->render(); >> >> ?> >> > >> > In your view script (used with the ViewScript decorator, as recomended >> > above), you could do exactly that, only easier: >> > >> > form->username ?> >> > >> >> As I see it, each element's data is protected and thus cannot be >> accessed >> >> from outside. Maybe I should try sub-classing Zend_
Re: [fw-general] Is anyone processing Zend_Form forms manually in the views?
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'); 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). 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 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) >> >> - form->getElement('username')->render(); >> ?> > > In your view script (used with the ViewScript decorator, as recomended > above), you could do exactly that, only easier: > > form->username ?> > >> 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.
[fw-general] Is anyone processing Zend_Form forms manually in the views?
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. Perhaps I want to create 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) - form->getElement('username')->render(); ?> 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. If someone has already done something similar, please do let me know. -- View this message in context: http://www.nabble.com/Is-anyone-processing-Zend_Form-forms-manually-in-the-views--tp16629046p16629046.html Sent from the Zend Framework mailing list archive at Nabble.com.