Jump to:

1971 Posts in 1275 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » DateField: dmyfields set as required field in Form

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

Page: 1
Go to End
Author Topic: 805 Views
  • Matze0681
    Avatar
    Community Member
    25 Posts

    DateField: dmyfields set as required field in Form Link to this post

    hi,

    i am trying to add a splitted up DateField ( via $dob->setConfig('dateformat', 'dmy'); ) as a required field
    in a Form. It seems like the default form validator canĀ“t handle seperate day,month,year fields as required fields. Did anybody had the same problem ?

    cheers
    matze

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: DateField: dmyfields set as required field in Form Link to this post

    In short no, I've never come across, but how about creating your own validator? Something like...

    class MyValidator extends RequiredFields {
       function php($data) {
          $bRet = parent::php($data);
          if (!customvalidation_fucntion($data['MyDate'])) {
             $obj->validationError('MyDate','MyDate must pass my validation',"required");
             $bRet = false;
          }
                
          return $bRet;
       }
    }

    805 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.