How to get html form element named - php variable

I want to receive an html form element by mail 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?'];

thank

+4
source share
5 answers

try this, use the $ _POST array in foreach:

action.php

foreach ($_POST as $key => $value)
echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";

Hope this will be helpful.

0
source

you can just put it like $_POST["{$name}"];
or
you can tie it like for example $_POST['abc_'.$name];

To make it more understandable See http://www.php.net/manual/en/language.types.string.php

0
source

.

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

name.

0

: print_r($_POST);

.

0

, . <form method="post" action="action.php"><input type="hidden" name="name" value="'.$name.'">

action.php: $var=$_POST['name']; echo $var;

, $.

, !

0
source

Source: https://habr.com/ru/post/1648997/


All Articles