Beispiel #1
0
function userExists($username, $password)
{
    return $username == "JohnDoe" && $password == "1234";
}
$form = VallI::create(['filePath' => 'externalErrorForm.php', 'dataKey' => 'data', 'params' => ['actionURL' => ''], 'classes' => ['invalid' => 'InvalidElement'], 'notToRestore' => ['password'], 'defaults' => [], 'onSubmit' => function ($form, $isValid) {
    /*
    	2) Now we need to check if user exists
    */
    $data = $form->getData();
    $message = "";
    $redirectionPath = "externalError.php";
    $messageType = "";
    if (!$isValid) {
        $message = "Vall-I does not like inserted data, saying: " . implode(", ", $form->getErrorMessages());
        $messageType = "danger";
    } else {
        if (!userExists($data['username'], $data['password'])) {
            // we need to call externalFormError method, because the form itself was valid, but there was an error during logging in
            $form->externalFormError();
            $message = "I am sorry, no user suits to data you entered.";
            $messageType = "danger";
        } else {
            $message = "Vall-I is satisfied with the following data, good job!<pre>" . print_r($form->getData(), true) . "</pre>";
            $messageType = "success";
        }
    }
    redirect($redirectionPath, ['text' => $message, 'type' => $messageType]);
}]);
?>
<!DOCTYPE html>
<html>
Beispiel #2
0
# lets define helper redirection function
function redirect($path, $message)
{
    $_SESSION['message'] = $message;
    Header("Location: " . $path);
    exit;
}
# and for fetching from post
function get($key)
{
    return isset($_POST[$key]) ? $_POST[$key] : null;
}
# require Vall-I.php file
require_once __DIR__ . "/../../src/Vall-I.php";
# create new instance of Vall-I class
$form = new VallI("basicsForm.php", ["action" => ""]);
/* ==== basic valli settings ==== */
# set CSS classes for invalid elements
$form->setClasses(['invalid' => 'InvalidElement']);
# set default form values
$form->setDefaults(['username' => 'John Doe']);
# set data restoring on failure
$form->restoreData = true;
# set inline error messages
$form->useInlineErrorMessages = true;
# init helper variable for messages. in case some message is stored in session, use it
if (!empty($_SESSION['message'])) {
    $message = $_SESSION['message'];
    $_SESSION['message'] = null;
} else {
    $message = null;
    $_SESSION['message'] = $message;
    Header("Location: " . $path);
    exit;
}
# init helper variable for messages. in case some message is stored in session, use it
if (!empty($_SESSION['message'])) {
    $message = $_SESSION['message'];
    $_SESSION['message'] = null;
} else {
    $message = null;
}
# require Vall-I.php file
require_once __DIR__ . "/../../src/Vall-I.php";
/* ============= VALL-I ITSELF ================= */
$form = VallI::create(['filePath' => 'basicsForm.php', 'dataKey' => 'data', 'params' => ['actionURL' => ''], 'classes' => ['invalid' => 'InvalidElement'], 'defaults' => [], 'notToRestore' => ['password'], 'onSubmit' => function ($form, $isValid) {
    $message = $isValid ? "Vall-I is satisfied with the following data, good job!<pre>" . print_r($form->getData(), true) . "</pre>" : "Vall-I does not like inserted data, saying: " . implode(", ", $form->getErrorMessages());
    redirect("initializing_via_static_method.php", $message);
}]);
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Basic usage of Vall-I</title>
		<style>
			.InvalidElement
			{
				border: 2px solid red;
			}
		</style>
	</head>
	<body>