Support » Plugin: Contact Form 7 » Using wpcf7_validate_ with foreach

  • Resolved harman79



    is it possible for someone to perform a custom validation using the wpcf7_validate_text filter for multiple text fields within the same function?

    Something like:

    add_filter( 'wpcf7_validate_text', 'cd_form_cond_val_texts', 20, 2 );
    function cd_form_cond_val_texts( $result, $tag ) {
    	$tag = new WPCF7_Shortcode( $tag );
    	$strings = array('old-street',
    		foreach($strings as $string) {
    			if (isset($_POST['cd-form-check-3']) && "your-{$string}" == $tag->name ) {
    				if (empty($_POST['your-{$string}'])) {
    				$result->invalidate( $tag, "xxxxxxxxx" );
    	return $result;

    This did return the xxxxxxxxx text for all fields defined in the array but actual validation did not work..
    Many thanks,

Viewing 1 replies (of 1 total)
  • Thread Starter harman79


    Nevermind… Of course it does this.. Its just that

    if (empty($_POST['your-{$string}']))

    should be

    if (empty($_POST["your-{$string}"]))

    Cheers for the great plugin.


Viewing 1 replies (of 1 total)
  • The topic ‘Using wpcf7_validate_ with foreach’ is closed to new replies.