I'm using Zend_Form with a registration page. I have a checkbox, that if checked, will show additional billing fields. In my form instance, I only want those extra fields to be setRequired(true) if that checkbox is checked. Is there a way to do this? The problem now is I have to set all the billing fields as setRequired(false), but if the user checks the checkbox, the logic won't care if the fields are empty because they aren't required.
A:
OK, so here is what I ended up doing. I created the billing information as a Zend_Form_SubForm and added it to the main Register form. Then, in my controller, on post, I check to see if the checkbox is checked. If its not, then I remove the subform from the main form and validate the form. If there is an error then I re-add the subform so the fields will show up when the form is re-drawn. Hopefully that will help somebody.
Jeremy Hicks
2010-09-09 16:44:12