Search code examples
phpformsurlgetappend

PHP add Get variabele to URL


I want to add a PHP GET variabele to the URL as soon as I post a GET Form, while keeping all other ?variabeles that are in the URL already.

If I submit my form now, all variables in the URL will be removed and replaced by the new submitted one. I only want to append the new variabele to the URL.

Does anyone know a solution?

The current URL for example is: XXX.php?name=text

The form that submits a search var:

<form  method="get" >
    <input name="search" type="text" placeholder="search">
</form>

The new URL would be XXX.php?search=text

I would like it to be: XXX.php?name=text?search=text


Solution

  • Submitting the form below

    <form action="XXX.php" method="get" >
        <input name="name" type="text" placeholder="search" />
        <input name="search" type="text" placeholder="search" />
    </form>
    

    will call the URL: XXX.php?name=text?search=text

    And if you want to not show an input for the user you just need to hide it with hidden="true":

    <input name="name" type="text" placeholder="search" hidden />