Is there a better way of designing zend_forms rather than using decorators?

There's a few ways. You can roll your own element view helpers (which could get rather clumsy soon I guess).

There's a few ways. You can roll your own element view helpers (which could get rather clumsy soon I guess). Or... you could use a viewscript for the form, like this (very basic example): class Your_Form extends Zend_Form { public function init() { $this->setDecorators( array( 'PrepareElements', array( 'ViewScript', array( 'viewScript' => 'path/to/viewscript.

Phtml' ) ) ) ); // only use basic decorators for elements $decorators = array( 'ViewHelper', 'Label', 'Errors' ); // create some element $someElement = new Zend_Form_Element_Text( 'someElement' ); // set the basic decorators for this element and set a css class $someElement->setDecorators( $decorators ) ->setAttrib( 'class', 'someCssClass' ); // add (potentially multiple) elements to this from $this->addElements( array( $someElement ) ); } } See the standard decorators section about PrepareElements for why it's needed to have the PrepareElements decorator set for the form, when using the ViewScript decorator. Then in the viewscript: element $form = $this->element;? > someElement->hasErrors() ):?

> someElement->renderErrors()? > someElement->renderLabel();? > someElement->renderViewHelper();?

Thanks, this is what I need. Cheers – Hanseh Apr 14 '10 at 3:51.

If you just want to set a class attribute on a form element, there is no need to define a decorator : this can be done using some standard methods of zend_form's elements. See the setAttrib() method, in the section Metadata and Attributes of the manual, and the example that's given there (quoting) : // Equivalent to $element->setAttrib('class', 'text'): $element->class = 'text; And if you can set a class attribute this way, you can probably set it while constructing your form's elements, or in a . Ini file that would define those elements -- there is an example that shows that a bit later in the page, in the Configuration section.

I agree with this answer for simple cases. But what if we have some sort of design complexity? Like having layered div with different form element per layer and the likes.

– Hanseh Apr 12 '10 at 9:26 In this (complex) case, I suppose you'll have to use decorators, yes. – Pascal MARTIN Apr 12 '10 at 10:42.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions