Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8760215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:59:19+00:00 2026-06-13T14:59:19+00:00

Possible duplicate: Hey there, I am building a form which is used to query

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:59:20+00:00Added an answer on June 13, 2026 at 2:59 pm

    The fact that you have are using select boxes makes this harder, but the general idea is to use the value of each select box in the $_REQUEST array to decide which option gets the selected attribute.

    Something along these lines:

    for ($i = 1993; $i <= $vehicleYear; $i++) {
        echo "<option value='".$i."'".(($_REQUEST['minimuimYearFilter']==$i)?"selected":"").">".$i."</option>";
    }
    

    The idea is that the option that was previously selected gets a selected attribute, making it the default selected value.

    This should work out of the box, at least in my example, the reason being that if no value is selected, none of them get a selected attribute and the top one is the default. If you also want a ‘first time’ selected option, simply detect if $_REQUEST[‘whatever’] has returned anything, and if not set its value to the option you want to be selected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: “BigInt” in C? Hey there! I'm calculating the Fibonacci numbers in C
Possible Duplicate: Sort a list of tuples by their second elements Hey there i
Possible Duplicate: Java REPL shell Hey, Is there any way to execute Java code
Possible Duplicate: Form validation Hey all, I'm just looking for what the correct way
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: multi image upload wrong quantity on file-upload Hey so I have a
Possible Duplicate: non static method cannot be referenced from static context hey i have
Possible Duplicate: Python program to find fibonacci series. More Pythonic way. Hey, i was
Possible Duplicate: Why does simple C code receive segmentation fault? Hey Everyone, I'm sure
Possible Duplicate: Can a Bash script tell what directory it's stored in? Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.