-
Notifications
You must be signed in to change notification settings - Fork 0
/
task14.php
124 lines (108 loc) · 2.97 KB
/
task14.php
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
$browserTypes = [
'None', 'FireFox', 'Chrome', 'Internet Explorer', 'Safari', 'Opera'
];
$speeds = [
'Unknown', 'DSL', 'T1', 'Cable', 'Dial Up', 'Other'
];
$os = [
'Windows', 'Linux', 'Macintosh', 'Other'
];
class Select
{
/**
* Name of the select field.
*/
public $name;
/**
* Values for the option field.
*/
public $value = '';
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function setValue($value)
{
if (!is_array($value)) {
exit("The given value {$value} is not an array.");
}
$this->value= $value;
}
public function getValue()
{
return $this->value;
}
public function makeOptions($optionValue)
{
foreach ($optionValue as $value) {
echo "<option value=\"{$value}\">{$value}</option>";
}
}
public function makeSelect()
{
echo '<select name="'. $this->getName().'">';
$this->makeOptions($this->getValue());
echo '</select><br />';
}
}
if (isset($_POST['submit'])) {
$name = trim($_POST['name']);
$username = trim($_POST['username']);
$email = trim($_POST['email']);
$browser = trim($_POST['browser']);
echo "The values you entered are: {$name}, {$username}, {$email}, {$browser}<br />";
echo 'Work Access<br />';
echo '<ul>';
echo '<li>'. $_POST['speeds'] .'</li>';
echo '<li>'. $_POST['os'] .'</li>';
echo '</ul>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Form Class</title>
</head>
<body>
<div class="form-container">
<form class="" action="task14.php" method="post">
<input type="text" name="name" value="<?php echo isset($_POST['name']) ? $_POST['name'] : ''; ?>"><br />
<input type="text" name="username" value="<?php echo isset($_POST['username']) ? $_POST['username'] : ''; ?>"><br />
<input type="text" name="email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?>"><br />
<?php
$selectBrowser = new Select();
$selectBrowser->setName('browser');
echo '<p>Work Access</p>';
if (isset($browserTypes)){
$selectBrowser->setValue($browserTypes);
$selectBrowser->makeSelect();
unset($selectBrowser);
}
echo '<p>Connection Speed</p>';
$selectSpeed = new Select();
$selectSpeed->setName('speeds');
if (isset($speeds)) {
$selectSpeed->setValue($speeds);
$selectSpeed->makeSelect();
unset($selectSpeed);
}
echo '<p>Operating System</p>';
$selectOs = new Select();
$selectOs->setName('os');
if (isset($os)) {
$selectOs->setValue($os);
$selectOs->makeSelect();
unset($selectOs);
}
?>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</body>
</html>