Skip to content

Commit 9ccebc0

Browse files
committed
Add number of invalid inputs
1 parent 9bc1d95 commit 9ccebc0

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

validate.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,80 +9,96 @@
99
<h1>Validation Result</h1>
1010
<?php
1111
$name = $email = $date = $dateInput = $time = $timeInput = $datetimeInput = $datetimeLocalInput = $month = $week = $number = $range = $color = "";
12+
$invalidInputs = 0;
13+
$invalidInputFormats = 0;
1214
$nameErr = $emailErr = $dateErr = $dateInputErr = $timeErr = $timeInputErr = $datetimeInputErr = $datetimeLocalInputErr = $monthErr = $weekErr = $numberErr = $rangeErr = $colorErr = "";
1315
if ($_SERVER["REQUEST_METHOD"] == "POST") {
1416
if (empty($_POST["name"])) {
1517
$nameErr = "Name is required";
18+
$invalidInputs++;
1619
} else {
1720
$name = htmlspecialchars($_POST["name"]);
1821
}
1922

2023
if (empty($_POST["email"])) {
2124
$emailErr = "Email is required";
25+
$invalidInputs++;
2226
} elseif (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
2327
$emailErr = "Invalid email format";
28+
$invalidInputFormats;
2429
} else {
2530
$email = htmlspecialchars($_POST["email"]);
2631
}
2732

2833
if (empty($_POST["date"])) {
2934
$dateErr = "Date is required";
35+
$invalidInputs++;
3036
} else {
3137
$date = htmlspecialchars($_POST["date"]);
3238
$dateTimestamp = strtotime($dateInput);
3339
if ($dateTimestamp === false) {
3440
$dateInputErr = "Invalid date format";
41+
$invalidInputFormats;
3542
}
3643
}
3744

3845
if (empty($_POST["time"])) {
3946
$timeErr = "Time is required";
47+
$invalidInputs++;
4048
} else {
4149
$time = htmlspecialchars($_POST["time"]);
4250
$timeTimestamp = strtotime($timeInput);
4351
if ($timeTimestamp === false) {
4452
$timeInputErr = "Invalid time format";
53+
$invalidInputFormats;
4554
}
4655
}
4756

4857
if (empty($_POST["datetimeInput"])) {
4958
$datetimeInputErr = "Datetime Input is required";
59+
$invalidInputs++;
5060
} else {
5161
$datetimeInput = htmlspecialchars($_POST["datetimeInput"]);
5262
}
5363

5464
if (empty($_POST["datetimeLocalInput"])) {
5565
$datetimeLocalInputErr = "Datetime Local Input is required";
66+
$invalidInputs++;
5667
} else {
5768
$datetimeLocalInput = htmlspecialchars($_POST["datetimeLocalInput"]);
5869
}
5970

6071
if (empty($_POST["month"])) {
6172
$monthErr = "Month is required";
73+
$invalidInputs++;
6274
} else {
6375
$month = htmlspecialchars($_POST["month"]);
6476
}
6577

6678
if (empty($_POST["week"])) {
6779
$weekErr = "Week is required";
80+
$invalidInputs++;
6881
} else {
6982
$week = htmlspecialchars($_POST["week"]);
7083
}
7184

7285
if (empty($_POST["number"])) {
7386
$numberErr = "Number is required";
87+
$invalidInputs++;
7488
} else {
7589
$number = htmlspecialchars($_POST["number"]);
7690
}
7791

7892
if (empty($_POST["range"])) {
7993
$rangeErr = "Range is required";
94+
$invalidInputs++;
8095
} else {
8196
$range = htmlspecialchars($_POST["range"]);
8297
}
8398

8499
if (empty($_POST["color"])) {
85100
$colorErr = "Color is required";
101+
$invalidInputs++;
86102
} else {
87103
$color = htmlspecialchars($_POST["color"]);
88104
}

0 commit comments

Comments
 (0)