-- Markus Wolff <[EMAIL PROTECTED]> wrote (on Monday, 03 March 2008, 04:06 PM +0100): > I'm currently taking my first steps with Zend_Form. Previously, I've used > Zend_Filter_Input for all my validation needs. > > I have a nice validator chain generator for ActiveRecord-like objects, so > that I don't need to write all validation rules by hand. The resulting > objects are not only used to validate forms, but also incoming data from > other data sources. > > I had always hoped I could reuse my existing Zend_Filter_Input objects once > I switch to Zend_Form for handling web forms, but I can't seem to find any > information on how to do this - is it at possible?
No. Zend_Form attaches validator and filter chains to the elements, not the form, so that elements can be re-used. Zend_Form then iterates over each element (and sub form) calling their isValid() methods. In other words, Zend_Form doesn't have a validator chain; Zend_Form_Element (and its descendants) does. > Something along the lines of: > > $validatorChain = $dataObject->getValidators(); > /* @var $validatorChain Zend_Filter_Input */ > $form = new Zend_Form(); > $form->setValidators($validatorChain); > > Or will I have to recreate all filter rules whenever I want to use > Zend_Form? Having two different mechanisms for that would not be an optimal > solution (to put it nicely :-)). Put an issue in the tracker if you'd like to be able to attach Zend_Filter_Input to Zend_Form; I'm not sure how much effort it would take, but it may be possible. However... Zend_Form will shortly be implementing Zend_Validate_Interface, which means you will be able to use it as your validator chain in your models -- i.e., it *could* replace Zend_Filter_Input for your models. -- Matthew Weier O'Phinney PHP Developer | [EMAIL PROTECTED] Zend - The PHP Company | http://www.zend.com/
