Distinguish forms within PHP

2

There is a way to distinguish forms within PHP, since I want every form to be sent to the same function, which will be responsible for passing $_GET to the proper function that can check the consistency of the form.

    
asked by anonymous 21.12.2014 / 19:35

1 answer

4

$_GET is not normally used with forms but $_POST .

The trick to distinguish is to use an identifying information from this form. In the most common case is to use a hidden field in HTML.

<input type="hidden" name="NomeDoFormulario" value="InformacaoAdicional">

Then you will receive% w / o% w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w Okay, you know what form it came from.

You can use other field types as well. There are those who like to use a $_POST["NomeDoFormulario"] field to identify. After all you can have each submit button in the / site with a different name.

<button type="submit" name="meuForm" value="true">Enviar</button>

PHP:

if (isset($_POST["meuForm"])) {
    //faz alguma coisa
}

It is possible to do something similar with "InformacaoAdicional" also, just send a field in query it.

    
21.12.2014 / 19:41