Support » Plugin: Contact Form 7 » Can’t check the WPML language inside wpcf7_validate_email

  • Resolved pako69

    (@pako69)


    Hi

    Below is a PHP code that try to validate an email.

    The validate process works.

    I also try to return a different error string regarding the current WPML languqge with wpml_current_language > https://wpml.org/wpml-hook/wpml_current_language/

    The issue is that the return languqge is always the same, or to be more precise, it always display the french string: ‘Seuls les e-mails professionnels sont autoris├ęs…’ regardless of the site language…

    Any idea?

    Thanks

    
    // Add custom validation for CF7 form fields
    
    function is_company_email($email){ 
    // Check against list of common public email providers & return true if the email provided *doesn't* match one of them
    
    $blocklist = array('mohmal.in','mohmal.com','neuf.fr','club-internet.fr','icloud.com','me.com','outlook.fr');
      
      	$parts = explode('@', $email);
      	$domain = end($parts);
    	
      	if (in_array($domain, $blocklist)) {
      		return false; 
    	} else {
    		return true;
    	}
    }
    
    function custom_email_validation_filter($result, $tag) {
    
    	$tag = new WPCF7_Shortcode( $tag );
    
    	if ( 'email' == $tag->name ) {
    
    		$the_value = isset( $_POST['email'] ) ? trim( $_POST['email'] ) : '';
    
    		if( apply_filters( 'wpml_current_language', null ) == 'fr' ) {
    			$strerror = 'Seuls les e-mails professionnels sont autoris├ęs...';
    		} else {
    			$strerror = 'Only business emails are allowed...';
    		}
    
    		if(!is_company_email($the_value)){
    			$result->invalidate( $tag, $strerror );
    		}
    	
    	}
    return $result;
    }
    
    add_filter( 'wpcf7_validate_email*', 'custom_email_validation_filter', 20, 2 );
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • pako69

    (@pako69)

    Hi
    I forget to tell you that I’m also using a cache plugin: LiteSpeed Cache.

    It seems that wp-nonce is cached this cause my issue.

    I find that if I disable CF7 Ajax, it works:
    add_filter( 'wpcf7_load_js', '__return_false' );

    Is there a more clean solution with Ajax working?

    Thanks

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    Posting about a commercial plugin is prohibited in these forums.

    pako69

    (@pako69)

    Hi Takayuki Miyoshi

    Where do you see I wrote about a commercial plugin ?!

    Yes I talk about WPML but how can you described an issue that exist betweed CF7 and WPML without mentioning it… ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.