This topic is locked

date condition

7/4/2008 6:12:38 AM
PHPRunner General questions
I
iripais author

Hi
I have a date field on a feedback form. How can I configure it not to accept dates before sysdate?

Sergey Kornilov admin 7/5/2008

You can use BeforeAdd/BeforeEdit events for this purpose.
Something like this might work:

$date1 = strtotime($values["DateField"]);

$date2 = strtotime("now");
if($date1 > $date2)

return true;

else

return false;
I
iripais author 7/5/2008

Thanks, it's working fine!! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=30824&image=1&table=forumreplies' class='bbc_emoticon' alt=':lol:' />
Now, how can I get to display a message like: "Date can´t be lower than today's date" when return false?

J
Jane 7/7/2008

Hi,
here is a sample:

if($date1 > $date2)

return true;

else

{

$message = "Date can´t be lower than today's date";

return false;

}

I
iripais author 7/8/2008

Perfect, thanks :.)

I
iripais author 7/10/2008

heyy, it's me again!!
I have another rookie question!!!
In this same form, I have tow other fields, one is "group_size" and the other is "group_size2"
How can I define in the same BeforeAdd/BeforeEdit events previously configured for the date, that group_size to, can´t be bigger than group_size?
Sorry about my english, I'm Portuguese :-\

J
Jane 7/11/2008

Hi,
here is a sample:

if($values["group_size"] > $values["group_size2"])

return true;

else

{

$message = "Group size 2 can´t be lower than group size";

return false;

}

I
iripais author 7/11/2008

It's not working!!
I'm prety sure that it's because I have mixted the events without the right syntax.
Here's what Iv´ve got:
//** Custom code ****

// put your custom code here
$date1 = strtotime($values["Arrival_date"]);

$date2 = strtotime("now");

$date3 = strtotime($values["Departure_date"]);
if($date1 > $date2 && $date3 > $date2)

return true;

else

{

$message = "Arrival and Departure date can´t be lower than today's date";

return false;

}
if($values["Group_size"]>$values["Group_size_act"])

return true;

else

{

$message = "Group size for activities can´t be bigger than booking group size";

return false;

}
What am I doing wrong?

J
Jane 7/11/2008

Try to use following code:

$flag1 = 1;

$flag2 = 1;

$date1 = strtotime($values["Arrival_date"]);

$date2 = strtotime("now");

$date3 = strtotime($values["Departure_date"]);
if($date1 > $date2 && $date3 > $date2)

$flag1 = 1;

else

{

$message = "Arrival and Departure date can´t be lower than today's date";

$flag1 = 0;

}
if($values["Group_size"]>$values["Group_size_act"])

$flag2 = 1;

else

{

$message = "Group size for activities can´t be bigger than booking group size";

$flag2 = 0;

}
if ($flag1 && $flag2)

return true;

else

return false;

I
iripais author 7/11/2008

Workin exacly the way I wanted it :-)
Thanks so much...