Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/exercises/form_uppgift/
form_uppgift2.php
form_uppgift3.php
form_uppgift5.php
form_uppgift6.php
hash.php
form_uppgift2.php
94 lines UTF-8 Windows (CRLF)
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Uppgift 1</title>
<style>
.flex {
display: flex;
align-items: center;
}
</style>
</head>
<body>
<form action="" method="post">
<label for="name">Namn:</label>
<input type="text" id="name" name="name" required>
<fieldset>
<legend>Frågor</legend>
<div class="flex">
<label for="q1">Hur mycket väger Helge? (<span id="a1"></span> kg)</label>
<input type="range" name="q1" id="q1" min="100" max="999" required>
</div>
<div>
Är Helge en älg?
<div>
<input type="radio" name="q2" id="q2:1" value="Ja" required>
<label for="q2:1">Ja</label>
<input type="radio" name="q2" id="q2:2" value="Nej">
<label for="q2:2">Nej</label>
<input type="radio" name="q2" id="q2:3" value="Kanske">
<label for="q2:3">Kanske</label>
<input type="radio" name="q2" id="q2:4" value="Jag vet inte">
<label for="q2:4">Jag vet inte</label>
</div>
</div>
<div>
Är Per en helg?
<div>
<input type="radio" name="q3" id="q3:1" value="Ja" required>
<label for="q3:1">Ja</label>
<input type="radio" name="q3" id="q3:2" value="Nej">
<label for="q3:2">Nej</label>
<input type="radio" name="q3" id="q3:3" value="Kanske">
<label for="q3:3">Kanske</label>
<input type="radio" name="q3" id="q3:4" value="Jag vet inte">
<label for="q3:4">Jag vet inte</label>
</div>
</div>
</fieldset>
<button type="submit">Skicka</button>
</form>
<script>
const q1 = document.getElementById('q1');
const a1 = document.getElementById('a1');
q1.addEventListener('input', () => {
updateAnswerDisplay();
});
updateAnswerDisplay()
function updateAnswerDisplay() {
a1.innerText = q1.value;
}
</script>
<?php
if (isset($_POST["name"]) && isset($_POST["q1"]) && isset($_POST["q2"]) && isset($_POST["q3"])) {
$correct_answers = 0;
if ($_POST["q1"] == '517') {
$correct_answers++;
}
if ($_POST["q2"] == 'Ja') {
$correct_answers++;
}
if ($_POST["q3"] == 'Kanske') {
$correct_answers++;
}
echo "Du heter " . $_POST['name'] . " och fick $correct_answers rätt.";
}
?>
</body>
</html>