Skip to content

Instantly share code, notes, and snippets.

@gareth-gillman
Created March 20, 2018 23:44
Show Gist options
  • Save gareth-gillman/1f1e733485183509a193febb888b3efb to your computer and use it in GitHub Desktop.
Save gareth-gillman/1f1e733485183509a193febb888b3efb to your computer and use it in GitHub Desktop.
Custom Array Validation for Contact Form 7
function gg_validation_filter( $result, $tag ) {
if ( 'your-name' == $tag[name] ) {
$items = array( '00','01','02' );
$post_item = $_POST['your-name'];
if( !in_array( $post_item, $items ) ) {
$result->invalidate( $tag, "This is not a valid zip!" );
}
}
return $result;
}
add_filter( 'wpcf7_validate_text*', 'gg_validation_filter', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment