Jump to content

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


edfou
Go to solution Solved by Ch0cu3r,

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!!

Link to comment
Share on other sites

  • Solution

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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.