Date Validation

Accumike
Posts: 15
Joined: 2011-09-06 08:10

Date Validation

Postby Accumike » 2013-07-10 15:00

Hi - I want to ensure that any date entered in a form is no more than 7 days ago.

I know how to ensure that the date is greater than current by using the {NOW} expression.

Does anyone know the syntax for 7 days ago? {NOW-7} and {NOW}-7 don't work.

Thanks in advance,

Michael Bullard
User avatar
Fred
Site Admin
Posts: 484
Joined: 2010-02-15 12:10
Location: Armagh, Northern Ireland
Contact:

Re: Date Validation

Postby Fred » 2013-07-11 15:58

Hi Michael
You obviously need to add a "Throw Error" behavior to the form and link it to your "date" field.

Then build your condition (Advanced Tab) like this:

Code: Select all

{date} < date('Y-m-d', strtotime('-7 days'))

{date} is your input field that you select from the dropdown for expression 1

This is what the line of code should look like when you are done

Code: Select all

$customTransaction->registerConditionalTrigger("{date} < date('Y-m-d', strtotime('-7 days'))", "BEFORE", "Trigger_ThrowError", 50);
Fred
eXel content Management Systems (XMS Systems)

Please click the "Accept the Answer" icon if you are happy with the response.
Accumike
Posts: 15
Joined: 2011-09-06 08:10

Re: Date Validation

Postby Accumike » 2013-07-12 12:09

Hi Fred,

Thanks for your help, this works very well. I even managed to include a dynamic date for 7 days ago in the error message, using a dummy recordset.

I have not really used the Throw Error function before - this has been a real eye opener.

Michael

Return to “MX Form Validation”

Who is online

Users browsing this forum: No registered users and 0 guests