The framework comes with a class to help you sanitize your inputs.
The framework comes with an Input
class that helps you retrieve form submitted data.
The
Input
class extends theIlluminate\Http\Request
.
$data = Input::all();
This will return an array with all submitted data found in a request.
$data = Input::get('name');
The code above returns the saved value for the name
key.
$data = Input::get('name', 'Foo');
If no name
value is found, the code returns the Foo
value.
$data = Validator::single($data, ['num', 'min:3']);
Pass an array of validation rules as a second parameter.
$data = Validator::multiple(Input::all(), [
'field-name' => ['alnum', 'min:5'],
'email' => ['email'],
'age' => ['num']
]);
Pass an array of validation rules as a second parameter where the key
is the data field name and its value is an array of validation rules.
Some rules accept extra parameters in order to validate your data. Simply add a colon after your rule followed by parameters separated by a comma.
$data = Validator::single($url, ['url:http, https']);
$data = Validator::single($age, ['num', 'min:1', 'max:2']);
Check the available rules below.
sanitize_text_field
function.esc_textarea
function.esc_html
function.sanitize_email
function.esc_url
function. You can pass arguments to the rule like so: ['url:http, https']
. See the WordPress reference for the list of protocols you can pass to the rule.['min:5']
.['max:25']
.true
if data equal to true
, 1
, on
and yes
. Returns false otherwise.wp_kses
function. You can pass arguments like so: ['kses:a|href|title, p']
.#2abb6f
or #ddd
.['file:jpg, gif, png']
.Made in Belgium