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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

Validate Dates


Go to End


721 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