-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask5.php
46 lines (39 loc) · 1.84 KB
/
task5.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
<?php
/**
* Author : Fabio Pinto
* Description as per requirements :
*Earlier, you created a function to display a form with a drop-down list. Using page 389 as a guide, adapt
*that function so that it uses a variable parameter list. That is, in the previous form, the number of
*parameters was fixed (two to set the target and the method, one to set the name of the form, and the
*other three to set the select options).
*In this task, the number of parameters passed to the function will vary. Specifically, the number of
*parameters passed will determine the number of drop-down list choices available.
*Contrary to the previous task, here the target and method is set. For this task, the function you are
*required to code, will create a drop-down list as shown in the screenshot below (you must code your
*OWN drop-down list options!). Note the first option needs to be (Select a …..).
**/
//Function that generates the form with variable parameter list
function task_5() {
//list parameters into array
$params = func_get_args();
//Count parameters passed
$num_params = func_num_args();
//Generate form
echo '<html>';
echo '<form action="task5.php" method=GET target=_blank>';
echo '<select name='.$params[0].'>';
//Generate drop down list from parameters not exceeding the length of the parameter list.
for($i = 1; $i < $num_params.length; $i++) {
echo '<option value="'.$params[$i].'">'.$params[$i].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Select">';
echo '</form>';
echo '</html>';
}
//Call to function
task_5("Months", "Select a month...", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
?>
</br><a href="index.html">Back...<a>
</br><iframe src="task5.txt" height="400" width="1200">
<p>Your browser does not support iframes.</p></iframe>