Title: Exclude form ID from function
Last modified: August 6, 2020

---

# Exclude form ID from function

 *  Resolved [jbslettebak](https://wordpress.org/support/users/jbslettebak/)
 * (@jbslettebak)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/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!
    -  This topic was modified 5 years, 10 months ago by [jbslettebak](https://wordpress.org/support/users/jbslettebak/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/exclude-form-id-from-function/#post-13219754)
 * Within a validation filter function you can retrieve the ID of the contact form
   by doing like the following:
 *     ```
       $submission = WPCF7_Submission::get_instance();
       $contact_form = $submission->get_contact_form();
       $contact_form_id = $contact_form->id();
       ```
   
 *  Thread Starter [jbslettebak](https://wordpress.org/support/users/jbslettebak/)
 * (@jbslettebak)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/exclude-form-id-from-function/#post-13222630)
 * Great, thank you for the help!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Exclude form ID from function’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [jbslettebak](https://wordpress.org/support/users/jbslettebak/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/exclude-form-id-from-function/#post-13222630)
 * Status: resolved