Make a "switch" in Zend Form to show/hide specific form elements

1.2k views Asked by At

I have working user registration form. It consist of Zend Form Elements. Now I wonder what is the best way to modify this form in order to implement a "switch" in registration form. In other words user should be able to choose which fields to fill (there should be fields as for individual user and company; only few elements should change their labels and "required" state of a selected registration type) and accordingly of made choice validate appropriate fields. So which is the best and not hard way to make it? Maybe there are some tutorial or examples? Thank you!

1

There are 1 answers

2
Marcin On BEST ANSWER

I think that the best place to change required" states and validators of your form elements is just before validating your form, i.e. $yourForm->isValid($_POST). In this place you would have to change the validators and/or required states of some fields. Which fields would depend on the value of registration type input form element.

As far as showing/hiding specific form elements goes, you could do it on the front-end side using JavaScript.