Morning, I have a web form that asks for the birth date of the user. It currently enters todays date automatically, but many users are clicking OK and entering that date instead of their birth date. I would like to set it up where it prompts the current date, but if the current date is entered it will refuse it and ask to be re-entered. So any date other than the current date would be acceptable. The code on the public form is: <label>Date of Birth</label> <?php echo HTML_FormTools::date_input('birth_date',$current['birth_date']) ?> PHP: ...and the "FormTools" entry for validation is: /* Creates a YYYY-MM-DD input and validates that the entry is valid. will strtotime anything passed as a string, should be YYYY-MM-DD though Hint: date('Y-m-d',$timestamp), or if you already have a date string, date('Y-m-d',strtotime($date)); This widget has buttons for incrementing the month, year and day, and won't allow fictional dates. Args: form_name - name of the form input_name - name of the input date - a date string or unix timestamp (date string should parse with strtotime()) */ function date_input($input_name, $date=null) { if (!$date) { $date = time(); } else if (is_string($date)) { $date = strtotime($date); } $yyyy = date('Y',$date); $mm = date('m',$date); $dd = date('d',$date); // months... $marr = array(); for ($i=1; $i<=12; $i++) { $t = mktime(0,0,0,$i,1,$yyyy); $m = date('F',$t); $mi = sprintf('%02d',$i); $marr[$mi] = $m; } //print_r($marr); $html = sprintf(' PHP: Cheers and Thanks...!
Well you are over complicating this for no reason. Simple logical operator can do this. <?php $today = date(d/m/y); $dob = $_POST['dob']; /* To gurantee form is submitted how you want use drop down lists so only certain format can be posted. */ if ($today == $dob) { echo "You cannot be born today"; }else{ // code here } ?> PHP:
Actually this is not my code. I inherited it and take absolutely no credit for it at all... You should see some of the other chunks. The one I posted is rather simple in comparison. hahaha Will try as you suggest. Cheers.