-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_2.php
50 lines (45 loc) · 1.12 KB
/
1_2.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
<!DOCTYPE HTML>
<html>
<head>
Bla bla
</head>
<body>
<?php
$name = $age = $birthdate = $nameError = $ageError = $birthdateError="";
if ($_SERVER["REQUEST_METHOD"]=="POST")
{ if (empty($_POST["name"])) {
$nameError = "Skriv inn navn";
}
if (empty($_POST["age"])) {
$ageError = "Skriv inn alder";
}
if (empty($_POST["birthdate"])) {
$birthdateError = "Skriv inn fødselsdato";
}
else{
$age = $_POST["age"];
$today = new Datetime(date('d.m.Y'));
$birthdate = new DateTime($_POST["birthdate"]);
$difference = $today->diff($birthdate);
if ($age != $difference->y) {
$birthdateError = "Alderen samsvarer ikke med fødselsdato!";
}
}
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
navn:<br>
<input type="text" name="name">
<span class="error"><?php echo $nameError;?></span><br>
<br>
Alder:
<input type="number" name="age">
<span class="error"><?php echo $ageError;?></span><br>
Fødselsdato:
<input type="date" name="birthdate">
<span class="error"><?php echo $birthdateError;?></span>
<br>
<input type="submit" value="Submit">
</form>
<?php
?>