Skip to content
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

Open
bwl21 opened this issue Aug 24, 2017 · 2 comments
Open

how can I make fields mandatory depending on another value #16

bwl21 opened this issue Aug 24, 2017 · 2 comments

Comments

@bwl21
Copy link
Contributor

bwl21 commented Aug 24, 2017

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.

screenshot_907

@jonasjonas
Copy link
Member

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.

@bwl21
Copy link
Contributor Author

bwl21 commented Sep 1, 2017

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"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants