Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Custom form with custom validation

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1160 Views
  • Jatinder
    Avatar
    Community Member
    23 Posts

    Custom form with custom validation Link to this post

    Hello,

    I am implemented a custom form with a custom template and it works fine.

    Besides other fields, the form has two phone number fields. I need to implement a validation "Input at least one phone number".

    How do I go about this?

    Thanks,
    Jatinder

  • Jatinder
    Avatar
    Community Member
    23 Posts

    Re: Custom form with custom validation Link to this post

    Would appreciate some help. Please respond!

  • patjnr
    Avatar
    Community Member
    101 Posts

    Re: Custom form with custom validation Link to this post

    Hi

    Hope this will help you

    function submit($data, $form) {
       
          
          
          if(empty($data['tel_1']) && empty($data['Tel_2'] ) ) {
             $form->addErrorMessage("tel_1",_t("ContactForm.TELEPHONEERROR","Please enter at least one Tel number."),"bad");
             // Load errors into session and post back
             Session::set("FormInfo.Form_ContactForm.data", $data);
             return Director::redirectBack();
             
          }

    this should work

    PAt

    1160 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.