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

Validate Dates


Go to End


1077 Views

Avatar
cumquat

Community Member, 201 Posts

21 January 2014 at 1:45am

Ok got an issue, i'm trying to work out how to validate a form/datobject, i have a start date for a task and an end date for the task, what i want to do is on the edit task form if the FinDate field is populated that it checks that the value is not less than the StartDate.

I've tried,

if(isset($_POST['FinDate'])) {
		 	if($_POST['FinDate'] < $_POST['StartDate']) {
            	$form->addErrorMessage('FinDate', 'End Date cannot be fore start date', 'bad');
            	return $this->redirectBack();
            }
		}

but this just keeps firing when no date is added and if a date is added it doesn't validate.

Any help or pointers much appreciated.

Mick