How can I check if a date entered in a field is not in the past??
So enetered date >= today
Thanks
You'll need to add custom validation - with JavaScript in the client and/or PHP on the server.
Bob
You'll need to add custom validation - with JavaScript in the client and/or PHP on the server.
Thanks for your quick reply Bob,
Could you give me an other hint how to do the JavaScript? I am a total newbee in Javascripting .....
look at the PHP function strtotime and use it in the server side validation box to do it, there is an example of PHP code beside the validation box, let us know your progress!
Regards
Max
look at the PHP function strtotime and use it in the server side validation box to do it, there is an example of PHP code beside the validation box, let us know your progress!
The only progress is more and more frustration..
This should be very simple I guess, but I am not a programmer so I cannot think of the script...
<?php
if(strtotime($_POST['accept_terms']) < strtotime(now))
return 'Sorry, date has to be in the future.';
?>
This is what I thought of, but unfortunatly I doesn't work. I will always return "Sorry, date has to be in the future."
So my if-statement alwys returns TRUE
the date field in your form is called "accept_terms" ??? you must use the correct field name of course, show me the date formt too, the PHP.net page of this function have some examples too, let me know!
Regards
Max
I did change the accept_terms field to my fieldname..
I have tried several things now. But my knowledge of PHP is not sufficient to get it to work..
The field I am checking is filled by the date/timepicker....
I have given up.. No check on my site :-(
Looking forward to the solution.
I am trying to do the same thing
I am using the date picker built in to chronoforms. So the date format is dd/mm/yyyy and in my form the id and name is comp_date
Here is the piece of code handling my date field. Note the id="comp_date" name="comp_date" You will need to match this in the php code.
<tr>
<td bgcolor="#D4D0C8"><label class="cf_label">Completion Date *</label><div class="form_element cf_datetimepicker"></div> </td>
<td bgcolor="#D4D0C8"><input onclick="new Calendar(this);" class="cf_datetime required" size="20" id="comp_date" name="comp_date" type="text" />
<a onclick="return false;" class="tooltiplink"><img src="components/com_chronocontact/css/images/tooltip.png" class="tooltipimg" border="0" height="16" width="16"></a>
<div class="tooltipdiv">Completion Date * :: Select the date which you need the completed document by.</div>
</tr>
The code the original poster put was so close. I had to change..
< to >
strtotime(now)) to strtotime('now'))
<?php
if(strtotime($_POST['comp_date']) > strtotime('now'))
return 'Sorry, date has to be in the future.';
?>
Please try this
<?php
$date_0 = JRequest::getVar('date_0', '', 'post');
// NB default format is dd/mm/yy
$date = explode('/', $date_0);
// change to yyyymmdd format
$date = $date[2].$date[1].$date[0];
// get today's date in the same format
$today = date('Ymd');
if ( $date < $today ) {
return "output: $date_0 is in the past!";
} elseif ( $date > $today ) {
return "output: $date_0 is in the future!";
} else {
return "output: $date_0 is today!";
}
?>
As written it always outputs an error message so modify the if clauses to meet your needs.
Parse error: syntax error, unexpected $end in /www/components/com_chronocontact/chronocontact.php(190) : eval()'d code on line 16
You must have read my mind. I started searching for a way to do this also. . . . I am using the date picker built in to chronoforms. So the date format is dd/mm/yyyy and in my form the id and name is comp_date
The code the original poster put was so close. I had to change..
< to >
strtotime(now)) to strtotime('now'))
<?php
if(strtotime($_POST['comp_date']) > strtotime('now'))
return 'Sorry, date has to be in the future.';
?>
Doesn't work for me.... never get the message with this piece of code...
Driving me crazy
There was a stray ' at the end of the 'future' line, try removing that and re-testing (I've fixed my earlier post).
Bob
Hi wwg,
There was a stray ' at the end of the 'future' line, try removing that and re-testing (I've fixed my earlier post).
Bob
Perfect !!!
Now it works!
This however is after the user clicks on SEND...
All other validations are done when loosing the focus off the field..
Is it hard to change the check to that point ?