This topic is locked
[SOLVED]

 How to ensure date entered is today or later?

4/24/2010 8:31:39 PM
PHPRunner General questions
author

Hello all,
I have a date field where users must enter a due date for a project. I would like to ensure that the date they enter is always in the future.
Right now I am allowing them to enter the date using a simple edit box with datepicker. Of course, this allows them to accidentally enter dates in the past.
Is there a function I can use to validate the entry is in the future and/or restrict entries to the future, or do I have to code a routine? If so, any links to examples would be greatly appreciated.
Thanks!

Sergey Kornilov admin 4/26/2010

You can do this using BeforeAdd/BeforeEdit events.
Here s the sample code. Replace date_field with your date field name.

$arr = db2time($values["date_field"]);

$end= mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);
if ($end<=time())

{

echo "Error";

return false;

}

else

{

return true;

}


More info:

http://xlinesoft.com/phprunner/docs/check_if_start_date_is_ealier_than_end_date.htm

5900 4/26/2010

Thanks a bunch.

5900 4/26/2010

Sergey,
Is it possible to insert error messages into a message block, so it stands out?
I did use this, which works.
echo "<script>alert('Oops! Your deadline must be in the future.')</script>";
But ideally, it would be nice to have it featured in a message block, just as "Record was added" does.
THANKS.



You can do this using BeforeAdd/BeforeEdit events.
Here s the sample code. Replace date_field with your date field name.

$arr = db2time($values["date_field"]);

$end= mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);
if ($end<=time())

{

echo "Error";

return false;

}

else

{

return true;

}


More info:

http://xlinesoft.com/phprunner/docs/check_if_start_date_is_ealier_than_end_date.htm

Sergey Kornilov admin 4/27/2010

Sure. Instead of echo "Error message"; assign error message to $message variable

$message = "Error message";


More info:

http://xlinesoft.com/phprunner/docs/before_record_updated.htm

5900 4/27/2010

Thanks, Sergey.



Sure. Instead of echo "Error message"; assign error message to $message variable

$message = "Error message";


More info:

http://xlinesoft.com/phprunner/docs/before_record_updated.htm