I have a search form with a submit button that looks like this:
<input type="submit" name="search_submit" value="Go"/>
I use the following php to handle this form:
if (isset($_GET['search_submit'])) { do blah }
Works fine. But my URL then contains &search_submit=Go. I don't want it to show up.
I know that to fix this problem I need to remove the name attribute from the form input row.
But my php doesn't work anymore and I don't know how to change it to handle the form. I tried changing it to:
if (isset($_GET['submit']))
and
if (isset($_GET['Go']))
But they don't work either. It would be great if someone could help me answer this.
P粉4641130782024-02-04 15:15:35
If you don't want to display the string in the URL
, you can use the POST
method. The main differences between GET
and POST
are as follows:
Obtain:
release:
Sample code:
if (isset($_POST["search_submit"])) { do blah }
P粉9564410542024-02-04 12:59:48
You cannot remove the name of an input element because PHP doesn't know which value to look for. If you want to completely hide the string behind the URL, use Request method POST GET
:
Your PHP will use the following:
$_POST['search_submit']; // Instead of $_GET['search_submit'];
A good answer on when to use GET and POST can be found here.
EDIT: If you just don't want the button to show up in the URL, but everything else should still be there (as per your comment), you can simply remove both The value and name of the submit button.
You can look for other values instead of looking for the one to set search_submit
:
if (isset($_GET['username'], $_GET['password'])) { // Do your stuff here }