0

I have 8 select fields with different options in each and im trying to pass each selected value into a querystring but im not sure how this work.

<form method="post">
  <fieldset>
    <legend class="hidden">Choose your options</legend>
     <ol>
      <li><label>option 1</label>
       <select>
        <option value="">Select one..</option>
        <option value="1">1</option>
        <option value="2">2</option>
       </select>
      </li>
      <li><label>option 2</label>
       <select>
        <option value="">Select one..</option>
        <option value="1">1</option>
        <option value="2">2</option>
       </select>
      </li>
      <li><label>option 3</label>
       <select>
        <option value="">Select one..</option>
        <option value="1">1</option>
        <option value="2">2</option>
      </select>
     </li>
    </ol>
   </fieldset>
  </form>

so ive got 8 of these and I want to select a value from each one and then press submit which will then bring up a best match from the values passed...

4 Answers 4

1

Read about Dealing with Forms.

You must give the form elements a name, e.g.:

<li><label>option 1</label>
   <select name="option1">
    <option value="">Select one..</option>
    <option value="1">1</option>
    <option value="2">2</option>
   </select>
</li>

Then you can access the value via $_POST['option1'].

Note: As you specified POST as form method, the data is not sent via the URL to your PHP script, but is contained in the request body. If you want to have the data in the URL (as querystring) you have to change the method to GET.

Sign up to request clarification or add additional context in comments.

Comments

0

I'm nut sure exactly what you're looking for, but if you put a name=".." attribute into your select tags, they'll end up into the querystring?

Comments

0

You are missing NAME argument from the SELECT TAG

Once you have this, options will be received by the php script in $_POST array.

So, for example:

<SELECT NAME="mySelect">
    <OPTION VALUE="V1">Value 1</OPTION>
    <OPTION VALUE="V2">Value 2</OPTION>
    ...
</SELECT>

You would read the value in your php script from $_POST['mySelect']

Also, keep in mind that you need to enter ACTION tag for your form, defining the php script that will execute once you send your form.

2 Comments

action is not needed. If not present, the data is sent to the current URL (which does not mean that it would not be good to use it ;) )
I suspected so, but wasn't sure and it sounded safer to say it's necessary ;)
0

Each <select> needs to have a name, for example, the first one could be <select name="firstSelection">. When you click submit, the browser sends something like firstSelection=1&secondSelection=&thirdSelection=1.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.