This topic is locked

Limiting Dates for Certain Fields

2/5/2008 1:08:51 AM
PHPRunner General questions
F
Frink09 author

Hi,
Great product! I'm still familiarizing myself with all of the tools and had a question about limiting dates. For example, I would like to be able to limit the years a user is able to choose when filling out a Credit Card Expiration date, as it stands now users are able to select 1908 as an expiration date which is obviously impossible!! I would also like to be able to limit the dates for a different field, say, date of work that was done. For the date of work field, the user might be able to select back twenty years, so 1988-2008. I checked the forums and found a similar topic, the Administrator told the user to:
[indent]"unfortunately we don't have a ready to go solution for this.

You need to edit generated calendar.html and include/calendar.js files to modify datepicker."[/indent]
I'm unsure how to go about editing these files to accomplish the desired result. Is it possible to stipulate different dates for different fields as I described above? Thank you very much in advance.

J
Jane 2/5/2008

Hi,
please see my answers below:

  1. I recommend you to use custom code for expiration date field: proceed to the Visual Editor tab, select Insert PHP code snippet on the toolbar and add your code.

    Here is a sample:
    ?>

    <select name=exmonth>

    <?php

    for ($i=1;$i<=12;$i++)

    {

    $currentmonth = date("n");

    if ($currentmonth==$i)

    {

    ?>

    <option selected><?php echo $i?></option>

    <?php

    }

    else

    {

    ?>

    <option><?php echo $i?></option>

    <?php

    }

    }

    ?>

    </select>

    <?php

    $start = date("Y",strtotime(now()));

    ?>

    <select name=exyear>

    <?php

    for ($i=$start;$i<$start+10;$i++)

    {

    ?>

    <option><?php echo $i?></option>

    <?php

    }

    ?></select><?php


Then construct correct date in the Before record added event on the Events tab.

Here is a sample:

//contruct expiration date

$values["expiration_date"]=$_REQUEST["exmonth"]."/".$_REQUEST["exyear"];
//check entered date

$val1 = date("Y",strtotime(now()));

$val2 = date("n",strtotime(now()));

$message = "<table class=shade><tr><td>Your card is expired. Please enter another card.</td></tr></table>";

if ($_REQUEST["exyear"]==$val1)

if ($_REQUEST["exmonth"]>=$val2)

return true;

else

{

echo $message;

return false;

}
if ($_REQUEST["exyear"]>$val1)

return true;

else

{

echo $message;

return false;

}



where expiration_date is your actual field name.
2. to limit dates for date of work field you can edit generated calendar.html and include/calendar.js files.