Reputation: 244
I want to get html form element by post with the name being a php variable
example :
<form method="post" action="action.php"><input type="submit" name="'.$name.'"></form>
action.php code:
$var=$_POST['What do i put here?'];
Thanks
Upvotes: 5
Views: 3989
Reputation: 244
I figured out how to do it .
<form method="post" action="action.php"><input type="hidden" name="name" value="'.$name.'">
action.php: $var=$_POST['name']; echo $var;
it displays the value of the input which is $name.
input can be whatever you want !!
Upvotes: 0
Reputation: 1300
Try This: print_r($_POST);
This is print all values with parameter.
Upvotes: 0
Reputation: 21
Try this.
$name = 'name';
$var = $_POST[$name];
The result will display the value of the name variable.
Upvotes: 0
Reputation: 506
you can simply put it like
$_POST["{$name}"];
or
you can concatenate it like
$_POST['abc_'.$name];
To make it more clear See http://www.php.net/manual/en/language.types.string.php
Upvotes: 0
Reputation: 3091
try this, use $_POST array in foreach:
action.php
foreach ($_POST as $key => $value)
echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
i hope it will be helpful.
Upvotes: 2