1. Go to this page and download the library: Download wixel/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/ */
/**
* Setting up the language, see available languages in "lang" directory
*/
$gump = new GUMP('en');
/**
* This is the most flexible validation "executer" because of it's return errors format.
*
* Returns bool true when no errors.
* Returns array of errors with detailed info. which you can then use with your own helpers.
* (field name, input value, rule that failed and it's parameters).
*/
$gump->validate(array $input, array $ruleset);
/**
* Filters input data according to the provided filterset
*
* Returns array with same input structure but after filters have been applied.
*/
$gump->filter(array $input, array $filterset);
// Sanitizes data and converts strings to UTF-8 (if available), optionally according to the provided field whitelist
$gump->sanitize(array $input, $whitelist = null);
// Override field names in error messages
GUMP::set_field_name('str', 'Street');
GUMP::set_field_names([
'str' => 'Street',
'zip' => 'ZIP Code'
]);
// Set custom error messages for rules.
GUMP::set_error_message('
/**
* You would call it like 'equals_string,someString'
*
* @param string $field Field name
* @param array $input Whole input data
* @param array $params Rule parameters. This is usually empty array by default if rule does not have parameters.
* @param mixed $value Value.
* In case of an array ['value1', 'value2'] would return one single value.
* If you want to get the array itself use $input[$field].
*
* @return bool true or false whether the validation was successful or not
*/
GUMP::add_validator("equals_string", function($field, array $input, array $params, $value) {
return $value === $params;
}, 'Field {field} does not equal to {param}.');
// You might want to check whether a validator exists first
GUMP::has_validator($rule);
/**
* @param string $value Value
* @param array $param Filter parameters (optional)
*
* @return mixed result of filtered value
*/
GUMP::add_filter("upper", function($value, array $params = []) {
return strtoupper($value);
});
// You might want to check whether a filter exists first
GUMP::has_filter($rule);