Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP $_POST, which part of the form does it connect to?

Tags:

html

php

This ia a beginner's question. If part of my form looks like this

<p>Subject name: <input type="text" name="menu" value="" 
                    id="menu_name" /></p>

and I want to use $_POST to get the data that is submitted, is $_POST reading the form "name" or "value" or "id."

For example, using the form above, would it be

$_POST['menu'];

or

$_POST['menu_name'];

or something else

like image 802
Leahcim Avatar asked Mar 26 '11 00:03

Leahcim


2 Answers

It uses the name attribute, and the value comes from the value attribute.

So you would access $_POST['menu'].

You can easily examine what's in a post with var_dump($_POST).

You could also view it directly with $HTTP_RAW_POST_DATA which is handy in some situations, or through the PHP protocol like so...

$post = file_get_contents('php://input');

Although this doesn't work with a form that has the enctype="multitpart/form-data" attribute.

The id attribute is never sent to the server.

like image 85
alex Avatar answered Oct 14 '22 12:10

alex


The key for the associative array is the name attribute of the form element.

like image 45
asthasr Avatar answered Oct 14 '22 11:10

asthasr