Skip to content

Instantly share code, notes, and snippets.

@dannyconnolly
Last active January 2, 2016 02:49
Show Gist options
  • Save dannyconnolly/8239359 to your computer and use it in GitHub Desktop.
Save dannyconnolly/8239359 to your computer and use it in GitHub Desktop.
Custom validation on Contact form 7 plugin
add_filter( 'wpcf7_validate_text', 'your_validation_filter_func', 10, 2 );
add_filter( 'wpcf7_validate_text*', 'your_validation_filter_func', 10, 2 );
function your_validation_filter_func( $result, $tag ) {
$type = $tag['type'];
$name = $tag['name'];
if ( 'your-id-number-field' == $name ) {
$the_value = $_POST[$name];
if ( is_not_valid_against_your_validation( $the_value ) ) {
$result['valid'] = false;
$result['reason'][$name] = "Error message here";
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment