Home  >  Q&A  >  body text

Handling Nameless Form Submit Buttons: A Guide

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粉348915572P粉348915572233 days ago314

reply all(2)I'll reply

  • P粉464113078

    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:

    • Parameters are retained in the browser history because they are part of the URL Bookmarks can be added.
    • The GET method should not be used when sending
    • Password or other sensitive information.
    • Maximum 7607 characters size.
    • Website example: new.php?category=sport

    release:

    • Parameters are not saved in browser history.
    • Cannot add bookmark.
    • POST method used when sending passwords or other content Sensitive information.
    • The maximum size of the POST method is 8 Mb.
    • Website example: new.php

    Sample code:

    if (isset($_POST["search_submit"])) {
        do blah
    }

    reply
    0
  • P粉956441054

    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
    }

    reply
    0
  • Cancelreply