Jump to content

sticky dropdown menu for dates; from today to minus 14 days


edfou

Recommended Posts

Can view form here. Need to add sticky quality!

http://www.cmfsc.ca/forms/FormsTesting.php

Here's my code. How do I modify to add sticky quality, to retain values after Submitting form?

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<? $startTime = mktime() - (2 * 3600); $endTime = mktime() - (14 * 24 * 3600);
print '<select name="newgameday">';
for ($i = $startTime; $i >= $endTime; $i = $i - 86400) {
$thisDate = date('l F jS Y', $i);
print "<option value=\"$thisDate\">$thisDate</option>\n";
}
print '</select>';
?>
<input type="submit" name="submit" value="Submit" />
</form>

 

Thanks for any help!!

When the form is submitted you need to compare the posted value to the value you're making in your for loop. If the values match add a selected attribute to the <option> tag.

<form action="" method="post">
	<select name="newgameday">
<?
$startTime = mktime() - (2 * 3600); $endTime = mktime() - (14 * 24 * 3600);

for ($i = $startTime; $i >= $endTime; $i = $i - 86400)
{
	$thisDate = date('l F jS Y', $i);

	// nothing selected by default
	$selected = '';

	// if the form is submitted. 
	// Check that the posted value is the same as this value
	// if is the same set it to selected.
	if(isset($_POST['newgameday']) && $_POST['newgameday'] == $thisDate)
		$selected = ' selected';

	// added the selected attribute here \/
	print "<option value=\"$thisDate\"$selected>$thisDate</option>\n";
}

?>
	</select>
	<input type="submit" name="submit" value="Submit" />
</form>

Lost my first login, had to create a new account. Anyway thanks a lot for both of your help!! Ch0cu3r your code is fantastic. Copy and Paste and I'm up and running. A two minute solution after many many hours. Thank you so much!

Great Forum!

Cheers

Ed

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.