ZF-7495: Add plugin interface to Zend_Form init() and validate()
Description
There needs to be a plugin interface for the global operations in Zend_Form. For init(), there needs to be a preInit() and postInit() method. A common situation for users is to override the decorators globally. Currently that means calling {{setElementDecorators()}} after adding the form elements:
class My_Login_Form extends Zend_Form
{
init()
{
//add elements
//call setElementDecorators
}
}
A more convenient way that would fit with the flexible nature of Zend_Form would be to provide a plugin interface for the init() method. So the user could create a global wrapper class, My_Form and then provide instructions for all forms.
class My_Form extends Zend_Form
{
preInit()
{
//set global form defaults, charset, etc.
}
init()
{
//this gets run if the extending class doesn't have an init() method
parent::init();
}
postInit()
{
//here we can do stuff after all the fields are added with init
}
preValidate()
{
//add a default validator
}
postValidate()
{
}
}
Then the user could extend this class for all forms instead of Zend_Form. If they didn't want the default for the form they could locally override postInit():
class My_Login_Form extends My_Form
{
init()
{
//add fields, postInit() will apply default decorators to all with setElementDecorators()
}
}
class My_Password_Form extends My_Form
{
init()
{
//add fields
}
postInit()
{
//override default decorator here because we don't want it.
}
}
This would add a great deal of flexibility and would only take about 6 lines of code in Zend Form.
Comments
Posted by Satoru Yoshida (satoruyoshida) on 2009-08-05T17:59:46.000+0000
Set component and auto reassign
Posted by Matthew Weier O'Phinney (matthew) on 2009-08-05T19:33:21.000+0000
This is a very interesting idea; can you please create a proposal for it so we can see if there might be other areas within Zend_Form that could use plugin support?
Once you do, please close this issue.
Posted by Rob Allen (rob) on 2012-11-20T20:52:42.000+0000
Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".
Feel free to re-open and provide a patch if you want to fix this issue.