ipla
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: [Contact Form 7] Custom validation on custom select don't workI’ve add these lines to my code and it’s not working. I’ve add an echo to validation function to debug and it not appears on form submit, so the plugin is not going through that function. Any idea?
Now, the code is:
/* "Centro" dropdown */ add_action( 'wpcf7_init', 'new_custom_wpcf7_shortcode_function' ); function new_custom_wpcf7_shortcode_function() { wpcf7_add_shortcode('centerdropdown', 'wpcf7_centerdropdown_shortcode', true); wpcf7_add_shortcode('centerdropdown*', 'wpcf7_centerdropdown_shortcode', true); } /* "Centro" dropdown - get "centros" and construct select */ wpcf7_add_shortcode('centerdropdown', 'wpcf7_centerdropdown_shortcode', true); wpcf7_add_shortcode('centerdropdown*', 'wpcf7_centerdropdown_shortcode', true); function wpcf7_centerdropdown_shortcode($tag){ global $post; $args = array( 'post_type' => 'centers', 'posts_per_page' => 100 ); $centers = get_posts( $args ); $output = '<select name="centerdropdown" class="centerdropdown form-control wpcf7-select wpcf7-form-control wpcf7-validates-as-required">'; $output .= '<option value="notselected">Centro</option>'; foreach ( $centers as $center ): $output .= "<option data-email='".get_post_meta( $center->ID, 'center_email', true )."' value='"; $output .= get_the_title($center); $output .= "'>".get_the_title($center)."</option>"; endforeach; $output .= "</select>"; return $output; } /* "Centro" dropdown - validation filter */ add_filter('wpcf7_centerdropdown', 'wpcf7_centerdropdown_filter', 10, 2); add_filter('wpcf7_centerdropdown*', 'wpcf7_centerdropdown_filter', 10, 2); function wpcf7_centerdropdown_filter( $result, $tag ) { echo '<h1>GOING THROUGH VALIDATION FUNCTION</h1>'; $value = $tag['type']; $name = $tag['name']; if($name == 'centerdropdown'){ $the_value = $_POST[$name]; if($the_value == 'notselected'){ $result['valid'] = false; $result['reason'][$name] = wpcf7_get_message( 'invalid_required' ); } } return $result; }
Viewing 1 replies (of 1 total)