Reputation: 41919
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
Upvotes: 5
Views: 458
Reputation: 10583
It is connected to the name
$name = $_POST['name'];
You can see the whole array of $_POST
by doing
var_dump $_POST;
Upvotes: 1
Reputation: 17169
$_POST['menu'];
would be the correect way. forms are connected to the name
Upvotes: 1
Reputation: 9397
The key for the associative array is the name
attribute of the form element.
Upvotes: 1
Reputation: 490153
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.
Upvotes: 7