Reputation: 6908
On my page, I have two dropdown boxes: One for a list of dates, and one for options. The box for dates is populated as such:
echo "<form name='selectedDate' action='page.php' method='GET' class='auto-style1'>";
echo "<select name='date' onchange='this.form.submit()'>";
echo "<option value=select>Select a Date</option>";
while ($row = mysql_fetch_array($result))
{
$date = date("m-d-Y",strtotime($row['date']));
if($date==date("m-d-Y"))
{
echo "<option>TODAY</option>";
}
else
{
echo "<option>" . $date . "</option>";
}
}
echo "</select>";
echo "<br />";
echo "<noscript>";
echo "<input type='submit' value='Select'>";
echo "</noscript>";
echo "</form>";
The other dropdown is populated as:
echo "<form name='selectedFormat' action='page.php' method='GET' class='auto-style1'>";
echo "<select name='option' onchange='this.form.submit()'>";
echo "<option value=select>Select a Option</option>";
echo "<option value=Artist>Artist</option>";
echo "<option value=Song>Song</option>";
echo "</select>";
echo "<br />";
echo "<noscript>";
echo "<input type='submit' value='Select1'>";
echo "</noscript>";
echo "</form>";
Now, you notice that both of them are set for Submit()
upon change. If I change the first one, the URL in the browser becomes page.php?date=02-26-2013
, and if I change the second one, the URL in the browser becomes page.php?option=Song
.
The problem that I'm having, is that if I change the date
to an older date, and then change the option
, my page reverts back to the date
being the current date. I've tried setting the action to a different URL:
$url = "musicInfo.php?date=" . $nonFormatedDate . "&option=" . $option;
And I changed both forms to have:
echo "<form action='" . $url . "' method='GET' class='auto-style1'>";
If I echo $url;
, it correctly displays what the browser URL should be. However, the browser URL is still populated by whichever dropdown I used last.
My question here is, how do I get both variables to be passed upon either submission?
So for instance, if I change the date
to be 01-13-2012
, and then change the option
to Song
, how can I ensure that the date
will be passed as well? And vice versa. Or, say if I change the date to 01-12-2012
, is it possible to have the date
dropdown box have this selected upon reload?
Site I'm trying to do: http://www.legendary-immersion.com/random/test.php
Upvotes: 2
Views: 885
Reputation: 63
As people say in comment you can submit only one form per request. So the best way is to hide data that you need in your form.
In your php file add this code
$date = isset($_GET["date"]) ? $_GET["date"] : "";
$option = isset($_GET["option"]) ? $_GET["option"] : "";
Then in first form add
<input type="hidden" name="option" value="<?php echo $option; ?>"/>
And in the second form add
<input type="hidden" name="date" value="<?php echo $date; ?>"/>
As the result in every form submit you will get the url like
page.php?date=yourdate&option=youroption
Best regards, Hope this will help
Upvotes: 1