View Full Version : Question about a sticky month selector and forms

08-15-2008, 01:30 AM
Hello all,

I have created this month selector which selects the current month. (I also have date and year ones like this too)

function months() {
echo '<select name="month">';
$months = array(
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'
foreach ($months as $m) {
echo '<option value="'.$m.'"';
if ($m == date('F')) {
echo ' selected="selected"';
echo '>'.$m.'</option>';
echo '</select>';

However, this selector is part of a multi-page form. And I can't seem to wrap my brain around figuring out how to make it 'sticky'. For example, if it's currently August, and the user selects "December", then clicks forward in the form and then backward (Back to the month selection page), it will read August again.

Here's the one for day too. This one would mystify me even more, as it works with a range of numbers.

function days() {
echo '<select name="day">';
$day = range(1,31);
foreach ($day as $d) {
echo '<option value="'.$d.'';
if ($d == date('j')) {
echo ' selected="selected"';
echo '">'.$d.'</option>';
echo '</select>';

Also, finally, I have a number of fields that are like this:

<input name="guestlist[]" type="text" size="20">
How can I make these sticky? I can't echo a whole array...

Any hints or nudges in the right direction would be much appreciated!
Thank you :)

Len Whistler
08-15-2008, 03:28 AM
Put the values into a session.

When ever a user changes the date it will re-write the session value, which would originally be set with the current date when the page loads.


08-19-2008, 01:35 AM
Thank you !!! That worked like a charm for the month/day dropdown.
Now I'm stuck on this one...

<select name="fromhour">
<option value="10"<? if ($_SESSION['fromhour'] == '10') { echo ' selected="selected"'; }?>>10</option>



These, for some reason, aren't retaining their value. And I've declared the variable in the email script

if (isset($_POST['fromhour'])) {
$_SESSION['fromhour'] = $_POST['fromhour'];

Any thoughts? Thank you so much for your help. :)

08-21-2008, 09:30 PM
Just in case someone prowls around here again, I solved the sticky fields where the entries were being put into an array. Instead of just defining that the entries were going into an array (like $guestlist[]) I put $guestlist['0'] to clarify. Then I echoed that value in PHP in the field. :thumbsup: