1. Go to this page and download the library: Download romangorbatko/gump library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Shorthand validation
is_valid(array $data, array $rules)
// Get or set the validation rules
validation_rules(array $rules);
// Get or set the filtering rules
filter_rules(array $rules);
// Runs the filter and validation routines
run(array $data);
// Strips and encodes unwanted characters
xss_clean(array $data);
// Sanitizes data and converts strings to UTF-8 (if available),
// optionally according to the provided field whitelist
sanitize(array $input, $whitelist = NULL);
// Validates input data according to the provided ruleset (see example)
validate(array $input, array $ruleset);
// Filters input data according to the provided filterset (see example)
filter(array $input, array $filterset);
// Returns human readable error text in an array or string
get_readable_errors($convert_to_string = false);
// Fetch an array of validation errors indexed by the field names
get_errors_array();
// Override field names with readable ones for errors
set_field_name($field, $readable_name);
# Note that filters and validators are separate rule sets and method calls. There is a good reason for this.
so.
$gump->validation_rules(array(
'username' => '=> ''noise_words'
));
$validated_data = $gump->run($_POST);
if($validated_data === false) {
echo $gump->get_readable_errors(true);
} else {
print_r($validated_data); // validation successful
}
/*
Create a custom validation rule named "is_object".
The callback receives 3 arguments:
The field to validate, the values being validated, and any parameters used in the validation rule.
It should return a boolean value indicating whether the value is valid.
*/
GUMP::add_validator("is_object", function($field, $input, $param = NULL) {
return is_object($input[$field]);
});
/*
Create a custom filter named "upper".
The callback function receives two arguments:
The value to filter, and any parameters used in the filter rule. It should returned the filtered value.
*/
GUMP::add_filter("upper", function($value, $params = NULL) {
return strtoupper($value);
});
class MyClass extends GUMP
{
public function filter_myfilter($value, $param = NULL)
{
...
}
public function validate_myvalidator($field, $input, $param = NULL)
{
...
}
} // EOC
$validator = new MyClass();
$validated = $validator->validate($_POST, $rules);