Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

DateField: dmyfields set as required field in Form


Go to End


2 Posts   1760 Views

Avatar
Matze0681

Community Member, 25 Posts

23 November 2010 at 1:14pm

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

Avatar
swaiba

Forum Moderator, 1899 Posts

2 December 2010 at 9:33pm

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;
	}
}