/ Published in: PHP
This is used privately simply to avoid retyping this all the time.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function dateControl($prefix,$session_prefix,$expire_year_start = 0) { // The prefix is used to be able to differenciate between controls in the event that multiple instances are used on the form // The session prefix is used to easily maitain the application-wide prefix used in the sesison variables just for naming purposes. // The expire_year_start variable is used to use as an offset due to the fact that the expiration year for passports will be // 10 years from the issue year. $year_control = '<select name="'.$prefix.'yearControl" id="'.$prefix.'yearControl">'; { if(isset($_SESSION[$session_prefix.$prefix.'yearControl']) && $_SESSION[$session_prefix.$prefix.'yearControl']==$y) { $year_control .= '<option value="'.$y.'" selected>'.$y.'</option>'; }else { $year_control .= '<option value="'.$y.'">'.$y.'</option>'; } } $year_control .= '</select>'; $month_control = '<select name="'.$prefix.'monthControl" id="'.$prefix.'monthControl">'; for($m = 1; $m <= 12; $m++) { if(isset($_SESSION[$session_prefix.$prefix.'monthControl']) && ($_SESSION[$session_prefix.$prefix.'monthControl']==$m || $_SESSION[$session_prefix.$prefix.'monthControl']=='0'.$m)) { $month_control .= $m > 9 ? '<option value="'.$m.'" selected>'.$m.'</option>' : '<option value="0'.$m.'" selected>0'.$m.'</option>'; }else { $month_control .= $m > 9 ? '<option value="'.$m.'">'.$m.'</option>' : '<option value="0'.$m.'">0'.$m.'</option>'; } } $month_control .= '</select>'; $day_control = '<select name="'.$prefix.'dayControl" id="'.$prefix.'dayControl">'; for($d = 1; $d <= 31; $d++) { if(isset($_SESSION[$session_prefix.$prefix.'monthControl']) && ($_SESSION[$session_prefix.$prefix.'dayControl']==$d || $_SESSION[$session_prefix.$prefix.'dayControl']=='0'.$d)) { $day_control .= $d > 9 ? '<option value="'.$d.'" selected>'.$d.'</option>' : '<option value="0'.$d.'" selected>0'.$d.'</option>'; }else { $day_control .= $d > 9 ? '<option value="'.$d.'">'.$d.'</option>' : '<option value="0'.$d.'">0'.$d.'</option>'; } } $day_control .= '</select>'; return $year_control.' '.$month_control.' '.$day_control.' yyyy/mm/dd'; }