Jump to:

1976 Posts in 1306 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » Validation for Custom Form

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

Page: 1 2
Go to End
Author Topic: 6380 Views
  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Validation for Custom Form Link to this post

    Glad to see you go it working, all looks kosher. The Email class will have populateTemplate() available to it in the next 2.3.0 release.

    Cheers,
    Sean

  • Tama
    Avatar
    Community Member
    119 Posts

    Re: Validation for Custom Form Link to this post

    Liam mentioned something that I thought existed - a required class automatically added to all of the required fields in forms.

    We've on 2.4.0 and I can't see the class anywhere in the HTML/CSS code or the DOM. Is there something I'm missing?

    Cheers
    Tama

  • Tama
    Avatar
    Community Member
    119 Posts

    Re: Validation for Custom Form Link to this post

    In the end I applied the "requiredField" class (used by the custom User Forms module) with the following code:

          // Set required fields in form object and assign classes
          $requiredFieldList = array('FirstName','LastName','Email');
          
          $validator = new RequiredFields($requiredFieldList);
          
          foreach($requiredFieldList as $fieldName) {
             $fields->fieldByName($fieldName)->addExtraClass("requiredField");
          }

    Thanks to this repo: http://sunny.svnrepository.com/sunny-side-up-general/trac.cgi/browser/userpage/code/RegisterAndEditDetailsPage.php?rev=73

    6380 Views
Page: 1 2
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.