$_GET gets ID or name value?

Asked

Viewed 1,335 times

4

The $_GET, or even the $_POST, take values from the ID of the input or of name?

<form action="#" method="get" name="meuForm">

<input id="nome" name="nome" type="text" value="Teste">

<input id="email" name="email" type="text" value="Teste">

</form>

When we do that: $_GET['nome'] or $_GET['email'], he’s gonna pull the ID="nome" or of name="nome"?

2 answers

5


Usually comes from name, is what the form uses to encode in the message or the request URL to the server, and so this is what PHP will receive.

Note that PHP does not know what comes, where it comes from, it does not understand HTML, JS, none of that. PHP picks up the HTTP communication, reading the URL in the case of $_GET, or reading the request in the case of $_POST.

You can even make a request that doesn’t use HTML as a basis. You can do it with JS on browser or an application that doesn’t even know what HTML is. So nothing prevents you from passing anything else. But the default HTML is name.

  • Ah, I get it, PHP only pulls the URL! I hadn’t thought of that.

  • 1

    From URL if request is GET, @Lucascarvalho. If POST is from the body of the request.

0

$_GET and $_POST take the values of the name, to get values via id, you must use javascript or jquery.

  • In the case kind that the bigown explained to me, ai would not be the name, but the URL. But thanks for the reply too!

Browser other questions tagged

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