Issues

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

Set component and auto reassign

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.

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.