/
task3.php
97 lines (78 loc) · 1.71 KB
/
task3.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
<?php
require_once 'functions.php';
$degrees = getValue($_POST, 'degrees');
$convFrom = getValue($_POST, 'degreesSelectFrom');
$convTo = getValue($_POST, 'degreesSelectTo');
$result = 0;
$output = '';
if ($convFrom == 'c' && $convTo == 'f') {
$result = (9/5) * $degrees + 32;
$output = 'Degrees in F: ';
} else if ($convFrom == 'f' && $convTo == 'c') {
$result = (5/9) * $degrees - 32*(5/9);
$output = 'Degrees in C: ';
} else if ($convFrom == $convTo && $convTo == 'c') {
$result = $degrees;
$output = 'Degrees in C: ';
} else if ($convFrom == $convTo && $convTo == 'f') {
$result = $degrees;
$output = 'Degrees in F: ';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Task3</title>
<style>
input {
width: 60px;
}
#submit {
width: 60px;
}
select {
margin-bottom: 10px;
}
</style>
</head>
<body>
<form action="" method="post">
<span>
<label for="degrees">Enter degrees:</label>
<input type="text" id="degrees" name="degrees" />
</span>
<span>
in:
<select name="degreesSelectFrom" id="degreesSelectFrom">
<option>--Choose option to convert from--</option>
<?= options([
'c' => 'C',
'f' => 'F',
], $degrees)
?>
</select>
</span>
<br />
<span>
Convert degrees to:
<select name="degreesSelectTo" id="degreesSelectTo">
<option>--Choose option to convert to--</option>
<?= options([
'c' => 'C',
'f' => 'F',
], $degrees)
?>
</select>
</span>
<input type="submit" id="submit" />
<p>
<?php
if ($_POST) {
echo $output . $result;
}
?>
</p>
</form>
</body>
</html>