Join 109,491 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,181 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
Please help! I'm trying to validate user age based on the DOB entered. If the user if 75 or over, an error message is generated. Currently, user is able to enter their DOB but if they enter July 1, 1933 (which would make them 75), no error is generated.
$diff = (dateDiff( "/", $vars['m_dob'], $today) / 365 ); //if( $diff < 0 ) // $errors[] = "You entered an invalid date. Please review and correct."; else if( $diff > 75 ) $errors[] = "Sorry. Our Membership program age limit is 75.";
HTML CODE
CODE
<tr> <th><label for="dob">Date of Birth</label>*<br /> <label class="small">Members must be under 75 years of age.</label></th> <td>{html_select_date prefix='mdate_' field_array='mdate' month_format='%m' month_empty='MM' day_empty='DD' year_empty='YYYY' start_year='-75' reverse_years='true'} </td> </tr>
/** * Smarty {html_select_date} plugin * * Type: function<br /> * Name: html_select_date<br /> * Purpose: Prints the dropdowns for date selection. * * ChangeLog:<br /> * - 1.0 initial release * - 1.1 added support for +/- N syntax for begin * and end year values. (Monte) * - 1.2 added support for yyyy-mm-dd syntax for * time value. (Jan Rosier) * - 1.3 added support for choosing format for * month values (Gary Loescher) * - 1.3.1 added support for choosing format for * day values (Marcus Bointon) * @link [url=http://smarty.php.net/manual/en/language.function.html.select.date.php]http://smarty.php.net/manual/en/language.f...select.date.php[/url] {html_select_date} * (Smarty online manual) * @version 1.3.1 * @author Andrei Zmievski * @param array * @param Smarty * @return string */ function smarty_function_html_select_date($params, &$smarty) { require_once $smarty->_get_plugin_filepath('shared','make_timestamp'); require_once $smarty->_get_plugin_filepath('function','html_options'); /* Default values. */ $prefix = "Date_"; $start_year = strftime("%Y"); $end_year = $start_year; $display_days = true; $display_months = true; $display_years = true; $month_format = "%B"; /* Write months as numbers by default GL */ $month_value_format = "%m"; $day_format = "%02d"; /* Write day values using this format MB */ $day_value_format = "%d"; $year_as_text = false; /* Display years in reverse order? Ie. 2000,1999,.... */ $reverse_years = false; /* Should the select boxes be part of an array when returned from PHP? e.g. setting it to "birthday", would create "birthday[Day]", "birthday[Month]" & "birthday[Year]". Can be combined with prefix */ $field_array = null; /* <select size>'s of the different <select> tags. If not set, uses default dropdown. */ $day_size = null; $month_size = null; $year_size = null; /* Unparsed attributes common to *ALL* the <select>/<input> tags. An example might be in the template: all_extra ='class ="foo"'. */ $all_extra = null; /* Separate attributes for the tags. */ $day_extra = null; $month_extra = null; $year_extra = null; /* Order in which to display the fields. "D" -> day, "M" -> month, "Y" -> year. */ $field_order = 'MDY'; /* String printed between the different fields. */ $field_separator = "\n"; $time = time(); $all_empty = null; $day_empty = null; $month_empty = null; $year_empty = null;
foreach ($params as $_key=>$_value) { switch ($_key) { case 'prefix': case 'time': case 'start_year': case 'end_year': case 'month_format': case 'day_format': case 'day_value_format': case 'field_array': case 'day_size': case 'month_size': case 'year_size': case 'all_extra': case 'day_extra': case 'month_extra': case 'year_extra': case 'field_order': case 'field_separator': case 'month_value_format': case 'month_empty': case 'day_empty': case 'year_empty': $$_key = (string)$_value; break;
// If $time is not in format yyyy-mm-dd if (!preg_match('/^\d{0,4}-\d{0,2}-\d{0,2}$/', $time)) { // then $time is empty or unix timestamp or mysql timestamp // using smarty_make_timestamp to get an unix timestamp and // strftime to make yyyy-mm-dd $time = strftime('%Y-%m-%d', smarty_make_timestamp($time)); } // Now split this in pieces, which later can be used to set the select $time = explode("-", $time);
// make syntax "+N" or "-N" work with start_year and end_year if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) { if ($match[1] == '+') { $end_year = strftime('%Y') + $match[2]; } else { $end_year = strftime('%Y') - $match[2]; } } if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) { if ($match[1] == '+') { $start_year = strftime('%Y') + $match[2]; } else { $start_year = strftime('%Y') - $match[2]; } }
Not sure I know what you mean. I've pasted the entire PHP code, so hopefully it clarifies. I tried removing the brackets (like the code you sent) and still did not receive an error. Thank you.