Jump to content

How to store selected data from a ComboBox


I3erk

Recommended Posts

I an quite new to web programming and i and trying to make a ComboBox for my website.

 

This ComboBox will be on a promo page for the website.

 

Right now, i created the ComboBox and it works perfectly. 

 

The next thing i want to do are 2 things (and have them done simultaneously):

 

1. when the submit button is clicked, i want it to save whatever is selected in the ComboBox into a database/spreadsheet, in order to determine the number of times the option is selected.

 

2. when the submit button is clicked, the client will then get sent to the website homepage.

 

Can anyone point me in the right direction as to how i can go about doing this?

 

Thanks.

 

I3erk

 

 

<form id="form1" name="form1" method="post" action="http://www.maisonsbellevue.com">
      <select name="frmhowhear" id="frmhowhear">
<option value="">Select one…</option>
<option value="Courrier Laval">Courrier Laval</option>
<option value="L'Étoile">L'Étoile</option>
<option value="Le Progress">Le Progress</option>
<option value="Le Richelieu">Le Richelieu</option>
<option value="Le Mirabel">Le Mirabel</option>
<option value="L'Information du Nord">L'Information du Nord</option>
<option value="Le Regional">Le Regional</option>
<option value="The Gazette">The Gazette</option>
<option value="Tremblant Express">Tremblant Express</option>
<option value="La Flèche">La Flèche</option>
<option value="Brochure">Brochure</option>
<option value="Recommendation">Recommendation</option>
      </select>
<input type="submit" value="Continue to Maisons Bellevue">
</form>

 

 

Link to comment
Share on other sites

ok so first of all you will need to set the action attribute of the form a php file. For example

 

<form id="form1" name="form1" method="post" action="processForm.php">

 

This file (processForm.php) would need to be in the same directory ('folder' if your a windows fanboy) as the file that contains the form.

Then in this php file you would need to fetch the selected options from the combobox which will be in the following variable

 

$_POST['form1']['frmhowhear'];

 

and will be an array.

 

You can then insert this into your database.

Once done you can redirect the user back to the home page by doing this:

header('Location: http://www.maisonsbellevue.com');

 

That should get you pointed in the right direction  :D

Link to comment
Share on other sites

Then in this php file you would need to fetch the selected options from the combobox which will be in the following variable

 

$_POST['form1']['frmhowhear'];

The form name is not sent in the $_POST array.

The correct variable will be $_POST['frmhowhear'] to grab the selected value.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.