It's not the exact same thing, but similar. I recently wrote a
Zend_Form_Element_Recaptcha class for adding a reCAPTCHA to a form. The
reCAPTCHA has two included input fields rather than the usual one. It's not
identical since reCAPTCHA is an online service and the input fields are
added dynamically to the form, but the principle is similar.

The main problems you'll have is attaching Validators. Each Validator
assumes you only validate one field (if you have two fields in one Element
class, the Element name can only reflect one of them). So you might need an
aggregate Validator to match your aggregate Element, and use the mysterious
$context parameter to the Validator's isValid() method (the reCAPTCHA
validator I use in the example accesses this). The context is basically a
reference to $_POST so you can access all form values from it.

Another problem someone noted was attached an aggregated Element to a
sub-form - it may not run the validation sequence as expected but I haven't
personally tested that yet.

If it's any help, I explored the whole custom reCAPTCHA Element/Validator
setup in Part 10 of my Zend Framework Blog Tutorial series over on
http://blog.astrumfutura.com

Paddy



Jean-Marc Fontaine wrote:
> 
> Hello,
> 
> I am trying to create a custom form element that aggregates several
> simple elements.
> 
> Has anyone already tried to do such an element ?
> 
> Regards,
> 
> Jean-Marc 
> 


-----
Pádraic Brady

http://blog.astrumfutura.com
http://www.patternsforphp.com
OpenID Europe Foundation - Irish Representative
-- 
View this message in context: 
http://www.nabble.com/-Zend_Form--Custom-aggregate-element-tp17670079p17673589.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to