Learn in-depth Zend_Form techniques to automate and power your applications forms, with or without using Zend Framework. Learn everything from setup of a form to custom elements and organizational best practices.
20. Decorator Pattern
BASICALLY: Wrappers for rendering
Element has list of decorators
Render Decorator n
Send output to Decorator n+1
Repeat until no more decorators
21. Decorator Pattern
2 “levels” of decorators
Form-Level
Element-Level
Form level decorator “FormElements” loops through
each element and triggers their render
26. Integrate Early
If you’re using custom decorators, set the prefix paths
EARLY. Constructor OR first few lines of init()
Optionally have an application-wide parent Form class
that all other forms extend
Here you can do common things like set the prefix
paths
30. Create Decorator
Override render()
Use an existing render from, say, HtmlTag, as a
starting point
Use array notation on any sub-fields
e.g. “fullyQualifiedName[foo]”, etc
31. Handle/Validate Input
Override setValue() and getValue()
setValue() will receive the value from $_FORM
(including sub-arrays, etc)
Override isValid() with caution:
isValid() calls setValue()
Possibly create custom Zend_Validate_ and
attach in the custom element
32. Using
$form->getPluginLoader(Zend_Form::DECORATOR)
->addPrefixPath('Namespace_Form_Decorator', '/path/to/decorators');
$form->getPluginLoader(Zend_Form::ELEMENT)
->addPrefixPath('Namespace_Form_Element', 'path/to/elements');