How can I prevent the user from selecting a date in the calendar field

In this article we will describe how to disable the date selection from a specific point forward (for example 2 days from today's date).

The first thing you need to do is to set the minimum date of the calendar field to a specific date, for example 01/01/2012 (the 1st of January 2012). After you have done this you will need to add a custom script in "Scripts called on form display" (you can find this field by going to Components > RSForm!Pro > Manage forms > select your form > Properties > PHP Scripts) that will take the minimum date and replace it with your custom date. The script presented below will disable the date selection for any dates that are before two days starting from the current date:

$futureDate = date('m/d/Y', strtotime("+2 days"));   
$formLayout = str_replace("{'mindate': '01/01/2012'}", "{'mindate': '".$futureDate."'}", $formLayout);

The first line will calculate the date two days from the current date using standard PHP functions and the second line will replace the default minimum date that you have set previously with your calculated date.

You can also control the month the calendar displays when the browse button is clicked by adding a new parameter to the calendar: pagedate . In order to control the month that is displayed when the calendar is opened you could try using:

$replace = "extra: Array({'mindate': '01/01/2012'})";
$with = "extra: Array({'mindate': '01/01/2012', 'pagedate': '10/2012'})";
$formLayout = str_replace($replace, $with, $formLayout);

You can also insert custom PHP scripts in the calendar field's Min Date and Max Date areas. The method described above is equivalent to the following example:


Adding the following code in the calendar field's Min Date tab will set the current date as the minimum selectable date for the calendar field:

return date('m/d/Y');

21 persons found this article helpful.

Was this article helpful?

Yes No
Sorry about that

You Should Also Read

Custom PHP code HOT

Display PHP variables by default when form is shown HOT

Custom validation rules HOT

PHP Scripts HOT

Controlling the calendar HOT