Title: [Contact Form 7]Validation for invit code
Last modified: August 21, 2016

---

# [Contact Form 7]Validation for invit code

 *  [Claymenia](https://wordpress.org/support/users/claymenia/)
 * (@claymenia)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/contact-form-7validation-for-invit-code/)
 * Hi,
 * I try to add in contact form 7 a field to validate an invitation code for send
   a mail.
 * i’ve add this :
 *     ```
       function wpcf7_add_shortcode_text() {
       	wpcf7_add_shortcode(
       		array( 'text', 'text*', 'email', 'email*', 'url', 'url*', 'tel', 'tel*', 'invit', 'invit*' ),
       		'wpcf7_text_shortcode_handler', true );
       }
       ```
   
 * I’ve try this :
 *     ```
       add_filter('wpcf7_validate_text','custom_text_filter_func', 10, 2);
       add_filter('wpcf7_validate_text*', 'custom_text_filter_func', 10, 2);
   
       function custom_text_filter_func( $result, $tag ) {
       	$type = $tag['type'];
       	$name = $tag['name'];
   
       	if ( 'invit' == $name ) { // <--- this line changed
       		$the_value = $_POST[$name];
   
       		if ( is_not_valid_against_your_validation( $the_value ) ) {
       			$result['valid'] = false;
       			$result['reason'][$name] = "Le code invitation est &eacute;rron&eacute;.";
       		}
       	}
   
       	return $result;
       }
       ```
   
 * and this :
 *     ```
       add_filter('wpcf7_validate_text','custom_text_filter_func', 10, 2);
       add_filter('wpcf7_validate_text*', 'custom_text_filter_func', 10, 2);
   
       function custom_text_filter_func( $result, $tag ) {
       	$type = $tag['type'];
       	$name = $tag['name'];
   
       	if ( 'invit' == $type ) { // <--- this line changed
       		$the_value = $_POST[$name];
   
       		if ( is_not_valid_against_your_validation( $the_value ) ) {
       			$result['valid'] = false;
       			$result['reason'][$name] = "Le code invitation est &eacute;rron&eacute;.";
       		}
       	}
   
       	return $result;
       }
       ```
   
 * And this shortcode :
 * `[invit* INVIT-TEST-CODE]`
 * But when i test my form, the field exist but form send an email than code field
   is good or not. No validation. No message concerning an error.
 * Can you help me ?

Viewing 1 replies (of 1 total)

 *  Thread Starter [Claymenia](https://wordpress.org/support/users/claymenia/)
 * (@claymenia)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/contact-form-7validation-for-invit-code/#post-4756480)
 * I’m inspirated by :
    [http://catsandcodes.blogspot.fr/2013/10/adding-custom-form-validation-to.html](http://catsandcodes.blogspot.fr/2013/10/adding-custom-form-validation-to.html)
 * and [http://wordpress.org/support/topic/plugin-contact-form-7-custom-field-validation-code?replies=12](http://wordpress.org/support/topic/plugin-contact-form-7-custom-field-validation-code?replies=12)
 * But i don’t understand why when i clic on send, form not compare field invit 
   with user code insert… and walidate the mail (with good code or not)…

Viewing 1 replies (of 1 total)

The topic ‘[Contact Form 7]Validation for invit code’ is closed to new replies.

## Tags

 * [add](https://wordpress.org/support/topic-tag/add/)
 * [code](https://wordpress.org/support/topic-tag/code/)
 * [contact-form](https://wordpress.org/support/topic-tag/contact-form/)
 * [field](https://wordpress.org/support/topic-tag/field/)
 * [validation](https://wordpress.org/support/topic-tag/validation/)

 * 1 reply
 * 1 participant
 * Last reply from: [Claymenia](https://wordpress.org/support/users/claymenia/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/contact-form-7validation-for-invit-code/#post-4756480)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
