-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how can I make fields mandatory depending on another value #16
Comments
Serverside, the easiest way is to subclass the HtmlForm class and override the onValidate function. I would also recommend defining your inputs in "addChildElements". There you can add a custom validator logic and also adjust the "required" attributes of your inputs. If you use client side validation you have to write some custom logic in javascript. |
I did not want to create an extra subclass of HtmlForm for every form i have. Your answer directed me to http://docs.depage.net/depage-forms/documentation/html/creditcard_8php_source.html where I found addChildElements This is the code which generates the form. Do I get it right, that I could even add a validator to the field set $fs3? $fs3 = $firstForm->addFieldset("fs_bill", ARRAY("label" => $t->__("Rechnung")));
$fs3->addSingle('person_bill', ARRAY('label' => $t->__('Rechnung bitte ausstellen an') ,
'required' => true, "class"=>"vrinput form_8col alpha omega",
// 'skin' => 'select',
'list' => $person_bill
)
);
//**** rechnungsanschrift
$fs3->addText("billto_name", ARRAY("label"=> $t->__("Name Rechnungsempfänger"), 'required' => false, "class"=>"vrinput form_8col alpha omega" ));
$fs3->addText("billto_street", ARRAY("label" => $t->__("Straße"), 'required' => false, "class"=>"vrinput form_8col alpha omega"));
$fs3->addHtml('<div class="cf"></div>');
$fs3->addText("billto_zip", ARRAY("label" => $t->__("PLZ"), 'required' => false, "class"=>"vrinput form_2col alpha"));
$fs3->addText("billto_city", ARRAY("label" => $t->__("Ort"), 'required' => false, "class"=>"vrinput form_6col omega"));
$fs3->addText("billto_country", ARRAY("label" => $t->__("Land"), 'required' => false, "class"=>"vrinput form_8col alpha omega"));
$fs3->addEmail("billto_email", ARRAY("label" => $t->__("Email"), 'required' => false, "class"=>"vrinput form_8col alpha omega")); |
In the following form, I would like to make the subsequent fields mandatory only if user choses "folgende Anschrift"
How can I achieve this? I tried to register a validator in the fields but this only fires if user has entered something there.
And even if, how can I create a more specific message to tell the user, what is wrong.
The text was updated successfully, but these errors were encountered: