Using HTML Fieldsets For PHP Form Arrays
I know you can use name arrays for multiple form inputs (e.g. , but can this also be used for entire fieldsets? How would this be manipul
Solution 1:
Alternatively, if you want such grouping you could create a grouping in your form such as this: consider this example:
<form method="POST" action="">
<fieldset>
Username: <input type="text" name="player[0][username]" />
Points: <input type="number" name="player[0][points]" />
</fieldset>
<fieldset>
Username: <input type="text" name="player[1][username]" />
Points: <input type="number" name="player[1][points]" />
</fieldset>
<br/>
<input type="submit" name="submit" />
</form>
When you process it:
if(isset($_POST['submit'])){
$all_players = $_POST['player'];
echo '<pre>';
print_r($all_players);
echo '</pre>';
}
It should yield something like this:
Array
(
[0] => Array
(
[username] => Test1
[points] => 1
)
[1] => Array
(
[username] => Test2
[points] => 2
)
)
Post a Comment for "Using HTML Fieldsets For PHP Form Arrays"