Built-in form action parameter is not passed via GET

Asked

Viewed 7,789 times

8

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

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

And I perform the Submit in the form (waiting for it to go to the page indicated in the action and take in GET the value "blue" typed in the form):

submit on form

But what happens is that it does not take the parameter spv which was part of the query string in the action, and is at the home of the project (panel.php).

Erro

Any suggestions?

  • 3

    When possible post the code and not the image of it, some proxys may block it.

3 answers

8


There is a conceptual problem in the code. Let’s look at the options for HTML form submission:

POST

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

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

GET

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

The values of the fields are concatenated in the URL:

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

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

Solution 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 only supports 2048 characters in the URL. The Apache HTTP server has a limit of 4000. See more details about limitations on HTTP browsers and servers at this link. A "safe" limit pointed by some is to limit the URL by up to 2000 characters.

Care should be taken when there are many fields in forms using the method GET, for a large size is quickly reached.

6

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

<form method="get" action="painel.php>
    <fieldset>
        <input type="hidden" name="spv" value="nav/buscaCard" /> 
        ...
    </fieldset>
</form>
  • this way worked out! Thanks... Only the bar passed in the value of the Hidden input that was so "spv=Nav%2FbuscaCard&query=blue". But finally it worked out I think it should be something related to the charset! Vlw

  • 2

    @Luitame Dispose, and do not forget that you can mark an answer as accepted if it solves your problem. As for the bar, this is normal - it was simply "escaped" to be correctly passed in the URL. Your server code (php) will receive a / correctly, as is expected.

5

In your action you leave only the file name.

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

and in php check that the value has been set and contains something.

if(isset($_GET['consulta']) && !empty($_GET['consulta'])){
  echo 'valor preenchido';
}else{
  echo 'valor vazio';
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.