Skip to content

Instantly share code, notes, and snippets.

@svenl77
Last active October 12, 2016 21:21
Show Gist options
  • Save svenl77/ac5b66ca137498d6af978707ea37754a to your computer and use it in GitHub Desktop.
Save svenl77/ac5b66ca137498d6af978707ea37754a to your computer and use it in GitHub Desktop.
<?php
//----------AFTER THE FORM HAS BEEN SUBMITTED----------
include("PFBC/Form.php");
if(!Form::isValid("<replace with unique form identifier>")) {
/* Validation errors have been found. We now need to redirect users back to the
form back so the errors can be corrected and the form can be re-submitted.
In case of ajax submit Form::renderAjaxErrorResponse () will build an error reply.*/
if ($reqIs("AJAX")) {
header ("Content-type: application/json");
Form::renderAjaxErrorResponse($formName);
} else
header("Location: <replace with form url>");
}
//form submitted data has been validated. Your script can now proceed with any further processing required.*/
// Custom Validation
// Often times, you'll find that you need to apply custom validation to your forms' submitted data. For instance, if you create a login form, you'll need to validate user entered credentials against your system. PHP-Bootstrap-Form has several methods that support this type of scenario. Let's take a look at an example implementation.
//----------AFTER THE FORM HAS BEEN SUBMITTED----------
include("PFBC/Form.php");
if(Form::isValid("login", false)) {
if(isValidUser($_POST["Email"], $_POST["Password"])) {
Form::clearValues("login");
header("Location: profile.php");
}
else {
Form::setError("login", "Error: Invalid Email Address / Password");
header("Location: login.php");
}
}
else
header("Location: login.php");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment