Using wpcf7_validate_ with foreach
-
Hi,
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', 'old-street-number', 'old-post-code', 'old-city', 'old-country', 'new-street', 'new-street-number', 'new-post-code', 'new-city', 'new-country'); 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,
Harry
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Using wpcf7_validate_ with foreach’ is closed to new replies.