• 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)
Viewing 1 replies (of 1 total)
  • The topic ‘[Contact Form 7]Validation for invit code’ is closed to new replies.