How it works.
v3, or vCube, is a script that builds a mail form and secures it by three levels of validation:
- PHP Anti spam tests
- PHP Validation
Morevoer, the script filters the data before sending them.
To do this v3
, and of a PHP validator: GUMP
. Adding some fuel with its own class: Vcube
Everything is ruled by a configuration array at the beginning of the vcube class, where the keys are the attribute
name of the form fields and the values are arrays with:
- The data to build the form
- The validation parameters for Js and PHP
- The sanitization rules for each field
The validation in PHP is made in two steps:
- Anti spam tests
The Anti spam tests to pass are three:
- is not a bot,
- hidden form field value,
- the form is compiled in a time range (2-3600 seconds).
If tests are ok, the script makes validation on the value of any single field using the valudation rules setted in the configuration array.
See the GUMP page in github to understand better the validation rules.
Moreover v3 adds to GUMP two validation rules.
- blacklist: validate against a list of words
- captcha: to validate the captcha
At the beginning of vcube.class.php set the email variables.
// Mail configuration
protected static $mail_cnf = "email@example.com";
protected static $site = "My site";
protected static $thanksPage = '';
Then configure your form fields in the field_map array. Here's a sample of how a field can be configured.
//Validation and Filtering options
//If label is omitted the default is the field name with first letter capitalized.
//If the field is 'required' the script will show an * after the label
//type: input/text' is the default value, it can be omitted
//placeholder, has a default value
//class, has a default value and can be omitted
//Specific attributes for Bootstrap Validator
'data-minlength-error'=>'The field needs to be 3 or longer in length.',
'data-remote-error'=>'The Name field is invalid',
How to write the
validation_rules and the
filter_rules is described in GUMP (the class used to make PHP validation).
type key to define the input field value in html, do in this way: input/text, input/email, input/url, input/number or textarea
class as in simple HTML
data-minlength-error key if you used