samoht Posted December 12, 2008 Share Posted December 12, 2008 hello, I have a form where the user has to fill out credit card info - I would like to supply the month and year always greater than or equal to the current month and year. So if the user selected month 12 then 2008 would be available for them (right now because its December 2008) but if they pick any other month 2009 would be the earliest year then could choose. here is how I currently have the arrays set up (hard coded) <td class="form2"><?php if(!$edit){ $xm = $_POST['expirationmonth']; echo '<input name="expirationmonth" size="3" type="text" value="'. $xm .'" readonly="readonly" >'; }else { //set up months $xmonths = array ('01','02','03','04','05','06','07','08','09','10','11','12'); echo '<select name="expirationmonth" class="required" '.$readonly.'>'; foreach($xmonths as $xmonth) { if (is_array($_POST['expirationmonth']) && in_array($xmonth,$_POST['expirationmonth'])) echo '<option selected value="'.$xmonth.'">'.$xmonth.'</option>'."\n"; elseif ( !$edit ) echo $xmonth; elseif ( $edit ) echo '<option value="'.$xmonth.'">'.$xmonth.'</option>'."\n"; } echo '</select>'; } ?> <span > / </span> <?php if(!$edit){ $xy = $_POST['expirationyear']; echo '<input name="expirationyear" size="3" type="text" value="'. $xy .'" readonly="readonly" >'; }else { //set up years $xyears = array ('08','09','10','11','12','13','14','15','16','17','18','19'); echo '<select name="expirationyear" class="required" '.$readonly.'>'; foreach($xyears as $xyear) { if (is_array($_POST['expirationyear']) && in_array($xmonth,$_POST['expirationyear'])) echo '<option selected value="'.$xyear.'">'.$xyear.'</option>'."\n"; elseif ( !$edit ) echo $xyear; elseif ( $edit ) echo '<option value="'.$xyear.'">'.$xyear.'</option>'."\n"; } echo '</select>'; } Any Ideas?? Thanks Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 12, 2008 Share Posted December 12, 2008 <?php $years = range(date('Y'), date('Y') + 11); print_r($years); ?> Quote Link to comment Share on other sites More sharing options...
samoht Posted December 12, 2008 Author Share Posted December 12, 2008 Thanks flyhoney, I'm not sure I fully understand though. how does this work of the selection of the month? Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 12, 2008 Share Posted December 12, 2008 I didnt really read your whole post, I was just providing an example of a better way to generate the array of months and years. Is this what you are looking for? <?php $year_start = date('Y'); $year_end = 2019; if ($_POST['expirationmonth'] < date('m')) { $year_start++; } $years = range($year_start, $year_end); $months = range(1, 12); ?> Quote Link to comment Share on other sites More sharing options...
samoht Posted December 12, 2008 Author Share Posted December 12, 2008 close but I need the year range to change based on the month without $_POST - so I guess I'll need to use ajax Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 12, 2008 Share Posted December 12, 2008 Oh, yeah. If you are trying to change the contents of select boxes without reloading the page you will need Javascript, but not necessarily AJAX. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.