-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
89 lines (72 loc) · 2.16 KB
/
index.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
<?php
require './vendor/autoload.php';
use Hilalahmad\Supervalidator\SuperValidator;
$customErrorMessages = [
// 'url.required' => 'url is required.aaaa',
// 'url.string' => 'url must be a string.',
'email.required' => 'email field is required.',
'email.email' => 'Invalid email address.',
'password.required' => 'Password is required.',
'password.confirmed:password_confirmation' => 'Password confirmation does not match.',
'password.password' => 'Custom error message for the password.',
];
$validator = new SuperValidator($customErrorMessages);
$data = [
'url' => ['required', 'date'],
'email' => ['required', 'email'],
'password' => ['required', 'confirmed:password_confirmation', 'password'],
];
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Assuming you have the SuperValidator class loaded and instantiated
if (!$validator->validate($data)) {
$errors = $validator->getErrors();
} else {
// Validation successful, process the form data
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
echo "Form submitted successfully!";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample Form</title>
</head>
<body>
<form action="" method="post">
<label for="name">Name:</label>
<input type="text" id="url" name="url">
<?php
if (isset($errors['url'])) {
echo $errors['url'];
}
?>
<br>
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<?php
if (isset($errors['email'])) {
echo $errors['email'];
}
?>
<br>
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<?php
if (isset($errors['password'])) {
echo $errors['password'];
}
?>
<br>
<label for="password_confirmation">Confirm Password:</label>
<input type="password" id="password_confirmation" name="password_confirmation">
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>