Retrieve selected value from select in PHP
Solved
crocus_61
Posted messages
24
Status
Member
-
crocus_61 Posted messages 24 Status Member -
crocus_61 Posted messages 24 Status Member -
Hello!
I'm starting, I'm starting, and I'm struggling... despite all the information found on this forum...
Here's my issue:
I propose a selection list with the following script:
<form action="select.htm" method="post">
<select name="cpLoc">
<option value="01001">CITY1</option><br>
<option value="01002">CITY2</option><br>
<option value="01003">CITY3</option><br>
</select>
</form>
and ... foolishly, I expected to be able to use the result of the selection on the next page, called by:
<form action="input_button.htm">
<input type="button" name="link" value="Start the search"
onClick="self.location.href='http://localhost/PageResultatRecherche.php'">
</form>
Here is the script for my "next page":
<?php
if (isset($_POST["cpLoc"])){
$cpLoc = $_POST["cpLoc"];
echo '*cpLoc selected ='.$cpLoc; (this was just for verification...)
}
else {
echo '*no selection !!';
echo '<br>';
}
?>
and .. indeed, I find myself with a nice "*no selection"...
Could someone please help me? There must be something I should know, an obvious thing... that is not obvious to me!
Thank you in advance!
I'm starting, I'm starting, and I'm struggling... despite all the information found on this forum...
Here's my issue:
I propose a selection list with the following script:
<form action="select.htm" method="post">
<select name="cpLoc">
<option value="01001">CITY1</option><br>
<option value="01002">CITY2</option><br>
<option value="01003">CITY3</option><br>
</select>
</form>
and ... foolishly, I expected to be able to use the result of the selection on the next page, called by:
<form action="input_button.htm">
<input type="button" name="link" value="Start the search"
onClick="self.location.href='http://localhost/PageResultatRecherche.php'">
</form>
Here is the script for my "next page":
<?php
if (isset($_POST["cpLoc"])){
$cpLoc = $_POST["cpLoc"];
echo '*cpLoc selected ='.$cpLoc; (this was just for verification...)
}
else {
echo '*no selection !!';
echo '<br>';
}
?>
and .. indeed, I find myself with a nice "*no selection"...
Could someone please help me? There must be something I should know, an obvious thing... that is not obvious to me!
Thank you in advance!
Configuration: Windows Vista Internet Explorer 7.0
1 answer
Hello,
1 - Your form with the button is not the same as your form with the list;
2 - You never submitted the form, you just called a page. For the browser, it’s exactly like if you typed the following page in the address bar: why would it remember the data that was entered before?
So I simply advise you to use only one form, which you define the "action" as the processing page, and for which you replace your button with a form submission button:
Xavier
1 - Your form with the button is not the same as your form with the list;
2 - You never submitted the form, you just called a page. For the browser, it’s exactly like if you typed the following page in the address bar: why would it remember the data that was entered before?
So I simply advise you to use only one form, which you define the "action" as the processing page, and for which you replace your button with a form submission button:
<form action="PageResultatRecherche.php" method="post"> <select name="cpLoc"> <option value="01001">CITY1</option> <option value="01002">CITY2</option> <option value="01003">CITY3</option> </select> <input type="submit" name="lien" value="Start the search"> </form>Hope this meets your expectations,
Xavier
I think I understood regarding the submission. Indeed...
So please, how do I make my submission if I have my 3 selection lists? Still in the same form?
What will the variables be named in the called page? It's the name indicated in "select name," right? I will retrieve them with $_POST['cpLoc'], for example?
Unless in special cases, we generally only need one form per page.
I've got a lot on my plate, and I think this is just the beginning!
It was really nice of you to help me!
See you!
Please check the site often... I'll probably have other issues!! (no, I don't want to overdo it! I need to look for it)
;-)