/
task1.php
99 lines (87 loc) · 1.88 KB
/
task1.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
98
99
<?php
require 'functions.php';
$month = getValue($_POST, 'month');
$day = getValue($_POST, 'day');
$year = getValue($_POST, 'year');
$validationErrors = [];
$result = '';
// checkdate($month, $day, $year) - returns true if the date is valid
if(!$_POST){
$result = 'Please enter a date:';
}else{
validateForm($validationErrors);
}
if(empty($validationErrors)){
$checkTheDate= checkdate($month, $day, $year);
if(!$checkTheDate){
$result = 'The date is NOT correct!';
}else{
$result = 'The date is correct!';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Date and Time - Task 1</title>
<style type="text/css">
body{
font-family: Helvetica;
font-size: 16px;
}
form > div {
margin: 0 0 3px 0;
}
form > div > label {
display: inline-block;
width: 100px;
}
form div.error {
color: red;
}
#main {
width:170px;
margin: auto;
background-color : #7ABF57;
color: #24391a;
padding:15px;
border-radius: 10px;
}
form div.error input,
form div.error select,
form div.error textarea {
border-color: red;
}
</style>
</head>
<body>
<div id="main">
<p> <?= $result ?></p>
<form method="post">
<div class="<?= getFieldErrorClass($validationErrors, 'month')?>">
<label for="month">Enter month:</label>
<input type="text" id="month" name="month"/>
<?= formErrors(getValue($validationErrors, 'month', [])) ?>
</div>
<br>
<br>
<div class="<?= getFieldErrorClass($validationErrors, 'day')?>">
<label for="day">Enter day:</label>
<input type="text" id="day" name="day"/>
<?= formErrors(getValue($validationErrors, 'day', [])) ?>
</div>
<br>
<br>
<div class="<?= getFieldErrorClass($validationErrors, 'year')?>">
<label for="year">Enter year:</label>
<input type="text" id="year" name="year"/>
<?= formErrors(getValue($validationErrors, 'year', [])) ?>
</div>
<br>
<br>
<input type="submit" />
</form>
</div>
</body>
</html>