Possible duplicate:
Hey there, I am building a form which is used to query an API and filter some search results. None of this data is being stored in a text file or a database.
Naturally the form submission refreshes the page, and the form values default to the native selected options I specified when writing the HTML. I am looking to store the users submitted values and have those be the selected options in the form after the page reloads and the filtered selections are loaded. What would be the best solution for achieving this? Sessions, or querying the POST array?
Naturally, I did a couple of Google Searches but everything related to databases or text files, which didn't apply.
My current form code:
<form method="post" action="">
<label>Year</label>
<select class="minYear" name="minimuimYearFilter">
<?php
$vehicleYear = date("Y") + 1;
for ($i = 1993; $i <= $vehicleYear; $i++) {
echo "<option value=".$i.">".$i."</option>";
}
?>
</select>
To:
<select class="maxYear" name="maximumYearFilter">
<?php
for ($i = 1993; $i <= $vehicleYear; $i++) {
if ($i == $vehicleYear) {
echo "<option value=".$i." selected>".$i."</option>";
} else {
echo "<option value=".$i.">".$i."</option>";
}
}
?>
</select>
<label for="priceFilter">Price</label>
<select class="priceFilter" name="priceFilter">
<?php
for ($i = 1000; $i <= 50000; $i=$i+1000) {
if ($i == 50000) {
echo "<option value=".$i.">$".$i."+</option>";
} elseif ($i == 20000) {
echo "<option value=".$i." selected>$".$i."</option>";
} else {
echo "<option value=".$i.">$".$i."</option>";
}
}
?>
</select>
<label for="mileageFilter">Mileage</label>
<select class="mileageFilter" name="mileageFilter">
<?php
for ($i = 5000; $i <= 100000; $i=$i+5000) {
if ($i == 100000) {
echo "<option value=".$i.">".$i."+</option>";
} elseif ($i == 75000) {
echo "<option value=".$i." selected>".$i."</option>";
} else {
echo "<option value=".$i.">".$i."</option>";
}
}
?>
</select>
<input type="submit" value="Submit">
</form>
Hey all, have a meeting, then out of town beyond wifi over the weekend, will catch up ASAP on Monday. Thanks for all the great responses thus far! Cant wait to get back and try this.