AnsPress 2.0: validation and sanitization

3.46K viewsUpdates
1

Added an easy method for form validation and sanitzation,
Here is an example:

$args = array(
	'title' => array(
		'sanitize' => array('sanitize_text_field'),
		'validate' => array('required' => true, 'length_check' => ap_opt('minimum_qtitle_length'))
	),
	'description' => array(
		'validate' => array('required' => true, 'length_check' => ap_opt('minimum_question_length'))
	),
	'is_private' => array(
		'sanitize' => array('only_boolean')
	),
);

$validate = new AnsPress_Validation($args);

var_dump($validate->get_sanitized_fields());
var_dump($validate->get_errors());