-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask015.php
More file actions
199 lines (182 loc) · 4.37 KB
/
task015.php
File metadata and controls
199 lines (182 loc) · 4.37 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
$browsers = array(
"None",
"Firefox",
"Chrome",
"Internet Explorer",
"Safari",
"Opera",
"Other"
);
$speed=array(
'Unknown',
'DSL',
'T1',
'Cable',
'DialUp',
'Other'
);
$os=array(
'Windows',
'Linux',
'Macintosh',
'Others'
);
class Select{
private $name; //select name
private $value ;//value
//this method sets the name of the select in html
public function setName($name){
$this->name = $name;
}
//get name
public function getName(){
return $this->name;
}
public function setValue($value){
if(!is_array($value)){
die("Error: values is not an array");
}
else{
$this->value = $value;
}
}
public function getValue(){
return $this->value;
}
//make option
public function makeOptions($value){
foreach ($value as $v ){
echo "<option value=\"$v\">" .ucwords($v). "</option>\n";
}
}
public function makeSelect(){
echo "<select name=\"" .$this->getName(). "\">\n";
//Create options.
echo "<option value= '`No response'> --Select one-- </option>\n";
$this->makeOptions($this->getValue());
echo "</select>" ;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Classes , methods and array</title>
</head>
<body>
<h2>User Registration<br /></h2>
<?php
if(!isset($_POST['submit'])){
?>
<form method="post" action="">
<p>Name:<br />
<input type="text" name="name" size="60" /> </p>
<p>Username:<br />
<input type="text" name="username" size="60" /></p>
<p>Email:<br />
<input type="text" name="email" size="60" /></p>
<p>Work Access:<br></p>
<p> Primary Browser :
<?php
//Instantiate object.
$select = new Select();
//Set properties.
$select->setName('browser');
$select->setValue($browsers);
$select->makeSelect();
?>
Speed:
<?php
//set propeties
$select ->setName('speed');
$select->setValue($speed);
$select->makeSelect();
?>
os:
<?php
//set propeties
$select ->setName('os');
$select->setValue($os);
$select->makeSelect();
?>
</p>
<p>Home Access:<br></p>
<p> Primary Browser :
<?php
//Instantiate object.
$select = new Select();
//Set properties.
$select->setName('browser_home');
$select->setValue($browsers);
$select->makeSelect();
?>
Speed:
<?php
//set propeties
$select ->setName('speed_home');
$select->setValue($speed);
$select->makeSelect();
?>
os:
<?php
//set propeties
$select ->setName('os_home');
$select->setValue($os);
$select->makeSelect();
?>
</p>
<input type="submit" name="submit" value="Go" />
</form>
<?php
//If form submitted, process input.
}else{
//Could include code to send data to database here.
//Retrieve user responses.
$name=$_POST['name'];
$username=$_POST['username'];
$email=$_POST['email'];
//The following variable has an altered name to avoid confusion.
$Browser=$_POST['browser'];
$OS = $_POST['os'];
$Speed = $_POST['speed'];
$Browser_home=$_POST['browser_home'];
$OS_home = $_POST['os_home'];
$Speed_home = $_POST['speed_home'];
if(empty($name)){
die('Error: Please enter your name. <br />
<input type="submit" name="back" value="Back to form"
onclick="self.location=\'task015.php\'" /> ');
}
if(empty($username)){
die('Error: Please enter your username. <br />
<input type="submit" name="back" value="Back to form"
onclick="self.location=\'task015.php\'" /> ');
}
$atSymbol = strpos($email, '@');
if(empty($email) || $atSymbol ==false){
die('Error: Please enter your email. <br />
<input type="submit" name="back" value="Back to form"
onclick="self.location=\'task015.php\'" /> ');
}
//Confirm responses to user.
echo "Data collected about $name: <br />";
echo "Username: $username<br />";
echo "Email: $email<br /> <br>";
echo "Work internet details<br>";
echo "Browser: $Browser<br />";
echo "OS: $OS <br>";
echo "Speed: $Speed<br><br>";
echo "Home internet details<br>";
echo "Browser: $Browser_home<br />";
echo "OS: $OS_home<br>";
echo "Speed: $Speed_home<br>";
}
?>
</body>
</html>