-
Notifications
You must be signed in to change notification settings - Fork 1
/
form_with_name_array.html
47 lines (31 loc) · 993 Bytes
/
form_with_name_array.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<title>Form with name array</title>
</head>
<body>
<form action="#" method="post">
<!--
With this weird person[0][first_name] names, it's possible
to access the $_POST variable more convenently as an
array.
-->
<b>First Person</b><br>
First name: <input name="person[0][first_name]" value="Peter" />
Last name: <input name="person[0][last_name]" value="Mayer" />
<p><b>Second Person Person</b><br>
First name: <input name="person[1][first_name]" value="Diana" />
Last name: <input name="person[1][last_name]" value="Muller" />
<p><input type="submit" value="Go">
</form>
<?php
foreach ($_POST['person'] as $person_no => $person_names) {
print "<p>Person " . $person_no . ":<br>";
foreach ($person_names as $attr => $name) {
print $attr . " = " . $name . "<br>";
}
}
?>
</body>
</html>