-- Markus Wolff <[EMAIL PROTECTED]> wrote (on Monday, 03 March 2008, 05:18 PM +0100): > Matthew Weier O'Phinney schrieb: > > > 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. > > So this would basically mean, I could do something like this? > > $form = $dataObject->getForm(); /* @var $form Zend_Form */ > $validatorChain = new Zend_Validate(); > $validatorChain->addValidator($form); > > I don't see how this would help though, as I can only validate single > values using Zend_Validate. Even if I use Zend_Filter_Input, I can use a > single Zend_Validate object only to validate a single field, not an array > of field values. > > I must be missing something here?
Yes. :-) Zend_Form_Element has a validator chain, allowing you to attach an arbitrary number of validators to any given element. Zend_Form then expects an array passed to isValid(), and then uses that to validate against the individual elements it contains. > Seems to me as if I'll have to decide whether I want to use Zend_Form for > all incoming data arrays, *or* Zend_Filter_Input. As I mentioned, if you'd like to see support for Zend_Filter_Input in Zend_Form, put an issue in the tracker. But my goal is to (a) have Zend_Form implement Zend_Validate_Interface so it can be used as a general purpose validator for sets of data (this will be done today or tomorrow), and (b) have ways to attach forms to models (and specifically Zend_Db_Table extensions) so that they models can have validators *and* be rendered as forms (probably in the 1.6.0 release). This latter will be a boon for those wanting to build quick-and-dirty CRUD apps. -- Matthew Weier O'Phinney PHP Developer | [EMAIL PROTECTED] Zend - The PHP Company | http://www.zend.com/
