-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·90 lines (71 loc) · 2.27 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
90
<?php
function dd(...$args)
{
echo "<pre>";
foreach ($args as $arg)
var_dump($arg);
echo "</pre>";
exit();
}
// Import the autoloader
require __DIR__ . '/vendor/autoload.php';
// Create a database connection, using a PDO reference
$db = require __DIR__ . '/db.php';
// Create the scout environment
$env = new Scout\ScoutEnvironment(__DIR__ .'/locale/en/scout.php', $db);
// Create some new constraints dynamically
$extendedConstraints = [
'field' => [
'test' => 'Scout\Constraints\Test\TestConstraint'
]
];
$extendedLocale = [
'field' => [
'test' => 'Custom message for the test constraint'
]
];
// Add the new constraints to the environment
$env->addConstraints($extendedConstraints);
$env->addLocale($extendedLocale);
// Create an instance of scout
$scout = new Scout\Scout($env);
if (!empty($_POST))
{
// Validate some fields
$result = $scout->validate(
[
// Filed name Field value Field rules
'firstname' => ['David', "required|alpha|lenmax(50)|test", []],
'lastname' => ['Ludwig', "required|alpha|lenmax(50)"],
'email' => ['example@domain.com', "required|email|unique('users','email')", ['unique' => 'That email already exists']],
'username' => ['SirDavid', "required|lenmin(3)|lenmax(25)"],
'password' => ['myPassword', "required|lenmin(6)"],
'repassword' => ['myPassword', "required|matches('password')"],
'creditcard' => [$_POST['creditcard'], "required|creditcard"],
],
[
'somefile' => [@$_FILES['somefile'], 'required|image']
]
);
// Print the errors for each of the fields
foreach ($result->all() as $error)
echo $error[0], '<br />';
if ($result->empty())
echo "No errors!";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Scout Validation Engine</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="somefile">
<label for="creditcard">Credit Card</label>
<input type="text" id="creditcard" name="creditcard">
<input type="submit">
</form>
</body>
</html>