-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathform_submit_multi_array.php
More file actions
executable file
·43 lines (43 loc) · 1.38 KB
/
form_submit_multi_array.php
File metadata and controls
executable file
·43 lines (43 loc) · 1.38 KB
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
<?php
$error = "";
if (isset($_POST['submit'])) {
if (isset($_POST['address']['postcode'])) {
// if (!preg_match('/^\w+$/', $_POST['address']['postcode'])) {
if (!ctype_alnum($_POST['address']['postcode'])) {
$error = "<p style='color:red;'><b>ERROR:</b>Postcode must be letters or numbers only!</p>";
}
}
}
?>
<html>
<body>
<form method=POST>
Here are some random checkboxes to keep you busy:
<p>
<input type="checkbox" name="option[key1][]" value="opt1">1
<input type="checkbox" name="option[key1][]" value="opt2">2
<input type="checkbox" name="option[key2][]" value="opt3">3
<input type="checkbox" name="option[key2][]" value="opt4">4
</p>
<table>
<tr><th>Address 1</th><td><input type="text" name="address[line1]" /></td></tr>
<tr><th>Address 2</th><td><input type="text" name="address[line2]" /></td></tr>
<tr><th>City </th><td><input type="text" name="address[city]" value='City' /></td></tr>
<tr><th>Postcode </th><td><input type="text" name="address[postcode]" /></td></tr>
</table>
<br /><input type="submit" name="submit" value="GO" />
</form>
<?php echo $error; ?>
<p>
<?php echo isset($_POST['address']['line1']) ? htmlspecialchars($_POST['address']['line1']) : 'NOT SET'?>
<?php
if (isset($_POST['address'])) {
foreach ($_POST['address'] as $key => $value) {
echo '<br />' . $key . ': ' . htmlspecialchars($value);
}
}
?>
</p>
<?php phpinfo(INFO_VARIABLES); ?>
</body>
</html>