Re: [gkornbluth] Input Date From Membership Signup Form
Hi Jerry,
There are a couple of things happening in your code.
First is where you're outputting your values for your option tags:
<option value="<?php echo htmlspecialchars(@$_REQUEST['$month_1']);?>">
In this code you're trying to output a request variable with an index of $month_1 instead of month_1. This will actually produce an error (the @ is suppressing it). Also, outputting the $_REQUEST variable for the value will mean that you'll be giving every option in the list the same value. What we want to use is $month_1. This is the incrementing values (between 1 and 12) that our foreach loop is producing.
To set a given value as selected, we'll use the selectedIf() function. This function checks the current value being used in the foreach loop against the value we want to default to that's in our request variable.
With these changes, our code looks like this:
<select name="month_1">
<?php foreach(range(1,12) as $month_1): ?>
<option value="<?php echo 'month_1';?>" <?php selectedIf($month_1,@$_REQUEST['month_1']);?>><?php echo date("F",strtotime("0000-$month_1"));?></option>
<?php endforeach ?>
</select> Day:
<select name="day_1">
<?php foreach(range(1,31)as $day_1): ?>
<option value="<?php echo $day_1;?>" <?php selectedIf($month_1,@$_REQUEST['day_1']);?>><?php echo $day_1;?></option>
<?php endforeach ?>
</select> Year:
<select name="year_1">
<?php foreach (range($lowestYear,$highestYear) as $year_1):?>
<option value="<?php echo $year_1;?>" <?php selectedIf($month_1,@$_REQUEST['year_1']);?>><?php echo $year_1;?></option>
<?php endforeach?>
</select>
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/