I am trying to pass vars from a form using drop down lists, that are populated by a query. It currently goes to result.php
<form action="result.php" method="post">
<SELECT NAME=Model class="normal">
<OPTION VALUE=0>Phone
<?=$model_o?>
</SELECT>
<SELECT NAME=Mins class="small">
<OPTION VALUE=0>Mins
<?=$minutes_o?>
</SELECT>
<SELECT NAME=Texts class="small">
<OPTION VALUE=0>Texts
<?=$texts_o?>
</SELECT>
<SELECT NAME=Freegifts class="big">
<OPTION VALUE=0>Choose Free Gifts
<?=$freegifts_o?>
</SELECT>
<SELECT NAME=Network class="normal">
<OPTION VALUE=0>Network
<?=$network_name_o?>
</SELECT>
<SELECT NAME=Merchant class="normal">
<OPTION VALUE=0>Contract/Prepay
<?=$merchant_category_o?>
</SELECT>
<br>
<button type="submit" value="search phones" class="red"><span>Sumbit</span></button>
</form>
However, what I want it to do is pass any variables from each drop down to the URL, only if a option is selected.
For example, if Model is selected it will pass the variable on to the URL when submit is select e.g. result.php?model=iphone and if both a model and mins is selected the URL would something like e.g. result.php?model=iphone&mins=500
I hope this makes sense as I am having difficulties explaining what I am actually trying to active.
Thanks in advance 🙂
Since you’re using GET, you can’t have it only send form fields that have data associated with them. Using GET will send everything about the form, including all fields, even if they don’t have any data. Are you able to parse it with Javascript or perhaps use POST instead?
Clarification
I say you’re using GET despite your form tag indicating POST because of your follow up (result.php?model….).