Reputation: 1379
I have form with changable content of textareas, from 1 to 5, each time with different names. I cannot modify the form itself.
how can i get number of textareas in form and names of them (it would be the best if i could do it clean in php without javascript).
the form is using method="POST"
and PHP version is 5.2+
EDIT: i forgot to tell you that i have only textareas in form.
Upvotes: 0
Views: 2415
Reputation: 107
if you post form to php script, $_POST
variable is array. then you can use something like this:
foreach($_POST as $v){}
to get every field.
Upvotes: 0
Reputation: 33502
You could do something along the lines of :
$count=0;
$formElements=array();
foreach ($_POST as $key => $val)
{
$count++;
$formElements[]=$key;
}
echo "The form as $count elements.";
var_dump($formElements);
If you want the values of the post you could make a two dimensional array like this:
foreach ($_POST as $key => $val)
{
$count++;
$formElements[]=array($key => $val);
}
Upvotes: 3