views:

232

answers:

1

I have a Zend Form with a subform which only is shown when the user selects a specific checkbox. Some of the fields in the subform are required IF the checkbox is selected, otherwise, the fields in that subform should be ignored by IsValid.

What would be the way to go here?

+2  A: 

Have you tried setting the element to not be required before validation? Something like...

$form = new My_Form();

if (isset($_POST['ignore_checkbox']) && $_POST['ignore_checkbox'] == 1)
{
    $form->getElement('ignored_element_name')->setRequired(false);

}

if ($form->isValid($_POST)) {
...
Typeoneerror
I know this is an options. However, I was hoping for a more elegant way.
sander