コード例 #1
0
<?php

use Kiernan\Validator;
use Kiernan\Session;
require '../../src/Kiernan/Validator.php';
require '../../src/Kiernan/Session.php';
Session::create();
$validator = new Validator(['name' => $_POST['name'], 'email' => $_POST['email'], 'ip_address' => $_POST['ip_address'], 'website' => $_POST['website'], 'age' => $_POST['age']], ['name' => 'required', 'email' => 'required|email', 'ip_address' => 'ip', 'website' => 'url', 'age' => 'required|integer']);
if ($validator->fails()) {
    Session::flash('old', $_POST);
    Session::flash('errors', $validator->messages());
    header('Location: index.php');
    exit;
}
Session::flash('success', 'Form submitted successfully');
header('Location: index.php');
コード例 #2
0
<?php

use Kiernan\Validator;
require '../../src/Kiernan/Validator.php';
$validator = new Validator(['name' => 'Kelly Kiernan', 'email' => '*****@*****.**', 'password' => 'secret', 'ip_address' => '192.168.0.1'], ['name' => 'required', 'email' => 'required|email', 'password' => 'required', 'ip_address' => 'required|ip']);
if ($validator->fails()) {
    print_r($validator->messages());
    exit;
}
echo 'Validation passed!';