-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformsubmit.php
More file actions
90 lines (84 loc) · 1.91 KB
/
formsubmit.php
File metadata and controls
90 lines (84 loc) · 1.91 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="en">
<!--
Display the POST and GET data sent by a form
Author: Phil Aylesworth
Date: 2017-03-23
Updated: 2018-01-10
-->
<head>
<meta charset="utf-8"/>
<title>Submitted Form Values</title>
<style>
body {
font-family: Helvetica, Arial, sans-serif;
box-sizing: border-box;
max-width: 800px;
margin: 0 auto;
padding: 0;
}
h1 {
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
border: 2px solid #555;
}
td,th {
border: 1px solid #555;
padding: 4px;
}
th {
background-color: #555;
color: white;
text-align: left;
border-color: white;
}
th:first-of-type {
width: 25%;
}
.warn {
color: red;
text-align: center;
}
</style>
</head>
<body>
<h1>Submitted Form Values</h1>
<?php
// The value might be an array of items. (IE checkboxes)
// If it is convert to a string.
// May as well trim and sanitize while we are at it.
function valueToString($arr) {
if(is_array($arr)) {
$new_value = '';
foreach ($arr as $v) {
$new_value .= trim($v) . ', ';
}
$new_value = substr($new_value, 0, -2);
} else {
$new_value = trim($arr);
}
return htmlspecialchars($new_value, ENT_HTML5);
}
if(count($_POST) == 0 && count($_GET) == 0) {
echo '<h2 class="warn">No data sent.</h2>';
}
if(count($_POST) > 0) {
echo '<h2>POST Values</h2><table> <thead><tr><th>Name</th> <th>Value</th> </tr> </thead> <tbody> ';
foreach ($_POST as $key => $value) {
echo '<tr><td>' . $key . '</td><td>'. valueToString($value) . '</td></tr>';
}
echo '</tbody></table>';
}
if(count($_GET) > 0) {
echo '<h2>GET Values</h2><table> <thead> <tr> <th>Name</th> <th>Value</th> </tr> </thead> <tbody> ';
foreach ($_GET as $key => $value) {
echo '<tr><td>' . $key . '</td><td>'. valueToString($value) . '</td></tr>';
}
echo '</tbody></table>';
}
?>
</body>
</html>