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 6979915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:56:49+00:00 2026-05-27T17:56:49+00:00

I have a form which POSTs to itselft so the user can do things

  • 0

I have a form which POSTs to itselft so the user can do things that you would find in a Shopping Cart.

e.g. Increase quantity, select postage type.

My problem is for my form Select element called “postage” whenever the form reloads itself , it forgets what was selected.

All my other fields remember their values using this:

<input type="text" name="postcode" value="<?php echo $_POST['postcode']; ?> " />

How do I use the $_POST value to automatically select the option in the select field that was done by the user?

I tried this:

<select name="postage" selected="<?php echo $_POST['postage']; ?>" >

and this

<select name="postage" value="<?php echo $_POST['postage']; ?>" >

Thanks

  • 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-05-27T17:56:49+00:00Added an answer on May 27, 2026 at 5:56 pm

    You almost got it. You need to set the attribute selected="selected" (the exact form you need technically depends on your HTML doctype, but this is a safe default) on the <option> element if and only if the value of $postage equals the value of the element. So:

    <select name="postage">
    <option value="foo" 
        <?php if ($_POST['postage'] == "foo") echo 'selected="selected" '; ?>
     >
    </select>
    

    Note that this violates the DRY principle because you now have two occurrences of the string "foo" in there, so it’s a prime candidate for refactoring. A good approach would be to keep value/text pairs in an array and iterate over it with foreach to produce the <option> tags.

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

Sidebar

Related Questions

I have a form which posts date information month, day, yeah, hour, minute, am/pm.
I have a view which contains a form, the form posts and the data
I have a form which takes both the user details and an image uploaded
I have a form/calculator, which posts to itself some data, this data is then
I have an controller that returns JSON. It takes a form, which validates itself
I have a form on which I POST the data with PHP. When the
I have a post html form, and the action is index.php, which is the
I have a page which should show a form with checkboxes, post back if
I have a form which is used to insert/display and update . In the
I have a form which has a lot of SELECTs. For various reasons, I'd

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.