-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask014.php
More file actions
188 lines (169 loc) · 3.78 KB
/
task014.php
File metadata and controls
188 lines (169 loc) · 3.78 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
<?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{
//Property
private $name; //String variable.
private $value; //Array variable.
//settor method for string name
public function setName($name){
$this->name = $name;
}
//getter mehod
public function getName(){
return $this->name;
}
//settor method for an array of values
public function setValue($value){
if (!is_array($value)){
die("Error: value is not an array.");
}
$this->value = $value;
}
//get values
public function getValue(){
return $this->value;
}
//This method creates the actual select options. It is private,
//since there is no need for it outside the operations of the class.
private function makeOptions($value){
foreach($value as $v){
echo "<option value=\"$v\">" .ucwords($v). "</option>\n";
}
}
//This method puts it all together to create the select field.
public function makeSelect(){
echo "<select name=\"" .$this->getName(). "\">\n";
//Create options.
$this->makeOptions($this->getValue());
echo "</select>" ;
}
}//end class
?>
<!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();
unset($select);
?>
</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'];
//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>