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/ */
// Username must be between 3-20 characters
'username' => 'between_len,3;20'
// Description between 10-500 characters
'description' => 'between_len,10;500'
// Works with Unicode characters
'title' => 'between_len,5;100' // Handles émojis, ñ, etc. correctly
> // ❌ Wrong - will break parsing
> 'field' => 'regex,/part|of;pattern/'
>
> // ✅ Correct - use array format
> 'field' => ['regex' => '/part|of;pattern/']
>
> // ✅ Good - equired|valid_email|max_len,255'
>
> // ❌ Less efficient - validates email format on empty values
> 'email' => 'valid_email|
> // All these become TRUE: '1', 1, 'true', true, 'yes', 'on'
> // All these become FALSE: '0', 0, 'false', false, 'no', 'off', null, ''
>
$filtered = GUMP::filter_input([
'title' => ' My Amazing Blog Post!!! ',
'description' => '<script>alert("xss")</script>This is a description with <b>bold</b> text.',
'price' => '$19.99 USD',
'active' => 'yes'
], [
'title' => 'trim|ms_word_characters|slug',
'description' => 'trim|sanitize_string',
'price' => 'sanitize_floats',
'active' => 'boolean'
]);
// Results:
// $filtered['title'] = 'my-amazing-blog-post'
// $filtered['description'] = 'This is a description with bold text.'
// $filtered['price'] = '19.99'
// $filtered['active'] = true
$gump = new GUMP('en'); // Set language
// Validate data without filtering
$validation_result = $gump->validate($_POST, [
'email' => 'ata (UTF-8 conversion)
$sanitized = $gump->sanitize($_POST, ['allowed_field1', 'allowed_field2']);
// Get detailed error information
if ($gump->errors()) {
$readable_errors = $gump->get_readable_errors(); // HTML formatted
$simple_errors = $gump->get_errors_array(); // Field => message array
}
// Set friendly field names for error messages
GUMP::set_field_name('usr_nm', 'Username');
GUMP::set_field_names([
'usr_nm' => 'Username',
'pwd' => 'Password',
'em' => 'Email Address'
]);
// Now validation errors will show friendly names
$is_valid = GUMP::is_valid(['usr_nm' => ''], ['usr_nm' => '
// Set custom error messages for validators
GUMP::set_error_message(' for {field}');
// Set multiple custom messages
GUMP::set_error_messages([
'
// Set language during instantiation
$gump = new GUMP('es'); // Spanish
$gump = new GUMP('fr'); // French
$gump = new GUMP('de'); // German
// Validation errors will now be in the selected language
$result = $gump->validate(['email' => 'invalid'], ['email' => 'valid_email']);
// Add a custom validator with callback
GUMP::add_validator('strong_password', function($field, array $input, array $params, $value) {
// Must contain at least 1 uppercase, 1 lowercase, 1 number, and 1 special char
return preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]/', $value);
}, 'The {field} must be a strong password with uppercase, lowercase, number and special character.');
// Usage
$is_valid = GUMP::is_valid(['password' => 'weak'], ['password' => 'strong_password']);
// Check if validator exists
if (GUMP::has_validator('strong_password')) {
echo "Custom validator is available!";
}
// Characters that will be replaced with spaces in field names for error messages
GUMP::$field_chars_to_spaces = ['_', '-', '.'];
// 'user_name' becomes 'User Name' in error messages
// 'first-name' becomes 'First Name' in error messages
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.