Reputation: 555
Ex. (HTML file)
<form name='test' method='POST'>
<input type='text' name='name'>
<input type='text' name='surname'>
<input type='submit' name='sub'>
</form>
Now in the PHP file I'll get the $_POST
like:
$_POST['name']= something
$_POST['surname']= something
etc...
What about if I want to "group" that to made a $_POST
like this:
$_POST[name-of-the-form]['name']= something
$_POST[name-of-the-form]['surname']= something
etc...
How could I do it?
Upvotes: 1
Views: 519
Reputation: 1283
Assuming you are doing this from a PHP file, you should use square braces andn the same name of in all element names:
<?php
$formName = 'test';
?>
<form name='<?=$formName?>' method='POST'>
<input type='text' name='<?=$formName?>[name]'>
<input type='text' name='<?=$formName?>[surname]'>
<input type='submit' name='sub'>
</form>
Upvotes: 0
Reputation: 1213
AbraCadaver is spot on here, all you do is name your form element accordingly. e.g.
<input type='text' name='name-of-the-form[name]'>
Upvotes: 1