Jump to content

array of years always greater than today?


samoht

Recommended Posts

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

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);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.