简体   繁体   中英

how to get a html form element with name is php variable

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

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.

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

Try this.

$name = 'name';
$var  = $_POST[$name];

The result will display the value of the name variable.

Try This: print_r($_POST);

This is print all values with parameter.

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 !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM