Exclude form ID from function
-
Hello,
I am running a custom function in my functions.php file that will require either the tel field or the email field to be required (user must fill in one or the other). I want this function to run on all forms except for one.
What I’m looking for is some snippet of code that I can use to check the ID of all the forms and then have this function run on all the forms except for the one I want to exclude.
Here is the function I’m using:
add_filter( ‘wpcf7_validate_tel’, ‘wpcf7_text_validation_filter’, 10, 2 );
add_filter( ‘wpcf7_validate_tel*’, ‘wpcf7_text_validation_filter’, 10, 2 );
add_filter( ‘wpcf7_validate_email’, ‘my_site_conditional_required’, 10, 2 );
add_filter( ‘wpcf7_validate_email*’, ‘my_site_conditional_required’, 10, 2 );function my_site_conditional_required($result, $tag) {
$tag = new WPCF7_Shortcode( $tag );$name = $tag->name;
$value = isset( $_POST[$name] )
? trim( wp_unslash( strtr( (string) $_POST[$name], ‘\n’, ‘ ‘ ) ) )
: ”;if ( ‘your-phone’ == $name ) :
if ( ” == $value && ” == $_POST[‘your-email’] ) :
$result->invalidate( $tag, wpcf7_get_message( ‘invalid_required’ ) );
endif;
endif;if ( ‘your-email’ == $name ) :
if ( ” == $value && ” == $_POST[‘your-phone’] ) :
$result->invalidate( $tag, wpcf7_get_message( ‘invalid_required’ ) );
endif;
endif;return $result;
}Please let me know if you have any questions.
Thank you!
- The topic ‘Exclude form ID from function’ is closed to new replies.