Parameter embedded in form action is not passed via GET


I have the following HTML code, and in the action section the address obeying my query string:

<form name="searchCard" class="serachCard" method="get" action="painel.php?spv=nav/buscarCard">
        <input type="text" name="consulta" />
        <input type="submit" name="" class="btnSearch" value="Buscar" />

And I submit it on the form (waiting for it to go to the page indicated in the action and give GET the "blue" value typed in the form):


Any suggestions?

asked by anonymous 20.12.2013 / 17:14

3 answers


There is a conceptual problem in the code. Let's look at the options for submitting HTML forms:


<form method="post" action="painel.php">

Form field values are sent in the request body. The URL is "free" for you to place additional parameters, but be careful not to use the same form field names.


<form method="get" action="painel.php">

Field values are concatenated in the URL:

  • painel.php?campo1=valor1&campo2=valor2

The body of the request goes empty and parameters placed "manually" in the action are lost. This is in line with HTML specification .

Workaround to include additional parameters in GET forms

Hidden fields ( hidden ):

<input type="hidden" name="campo" value="valor"/> 

Limitations of the GET method

It is not recommended to use very large URLs as this can cause errors. For example, Internet Explorer supports only 2048 characters in the URL. The Apache HTTP server has a limit of 4000. See more details on limitations in HTTP browsers and servers in this link . A "safe" limit pointed out by some is limiting the URL by up to 2000 characters.

Care must be taken when there are too many fields in forms that use the GET method, because you quickly reach a large size.

20.12.2013 / 17:44

If I understand correctly, your problem is that the spv parameter is not being passed, right? I suggest putting it in a hidden input ( hidden input):

<form method="get" action="painel.php>
        <input type="hidden" name="spv" value="nav/buscaCard" /> 
20.12.2013 / 17:31

In your action, leave only the file name.

<form method="get" action="painel.php">

and in php make sure the value has been defined and contains something.

if(isset($_GET['consulta']) && !empty($_GET['consulta'])){
  echo 'valor preenchido';
  echo 'valor vazio';
20.12.2013 / 17:19