Adding Validation to a WordPress Creation Toolkit Field

, , , ,

So I ran into a need to validate an email address for a frontend posting of a custom post type using Cozmos Labs WordPress Creation Toolkit.  Here is the code that I used to be able to accomplish that.  There is some commented out code that allows for you to see what is being passed in the field and values variables

add_filter('wck_extra_message', 'wckc_text_as_email', 10, 6);
function wckc_text_as_email($message, $field, $required_fields, $meta, $values, $id) {

	/*
	echo "<pre>";
	var_dump($field);
	var_dump($values);
	echo "</pre>";
	die();
	*/

	if ($field[0]['slug'] == 'email') {
		if(!filter_var($values['email'], FILTER_VALIDATE_EMAIL))
			return 'Please enter a valid Email Address !';
	}
}

 

Skills

Posted on

June 23, 2017

Submit a Comment

Your email address will not be published. Required fields are marked *