Validate field select box custom
-
Hi, i have create a custom add shortcode for extract field from db table by select box.
All work ok, but Now i don’t find a solution to validate this field.Any ideas?
wpcf7_add_shortcode('postdropdown', 'createbox', true); function createbox(){ global $wpdb; $campocustom = $wpdb->get_results( "SELECT * FROM db_ippbrescia.wpipp_ai1ec_events WHERE contact_name IS NOT NULL AND contact_name != '';" ); $output = "<span class='wpcf7-form-control-wrap cursus'><select name='cursus' class='wpcf7-form-control wpcf7-select wpcf7-validates-as-required' aria-required='true' id='cursus' onchange='document.getElementById(\"cursus\").value=this.value;'><option>---</option><span>"; foreach ( $campocustom as $custom ) : setup_postdata($custom); /** echo $custom->contact_name; **/ $title = ($custom->contact_name); $output .= "<option value='$title'> $title </option>"; endforeach; $output .= "</select>"; return $output; }
i have added this code but not work
add_filter( 'wpcf7_validate_postdropdown', 'your_validation_filter_func', 10, 2 ); add_filter( 'wpcf7_validate_postdropdown*', 'your_validation_filter_func', 10, 2 ); function your_validation_filter_func( $result, $tag ) { $type = $tag['type']; $name = $tag['name']; if ( 'postdropdown' == $name ) { $the_value = $_POST[$name]; if ( is_not_valid_against_your_validation( $the_value ) ) { $result['valid'] = false; $result['reason'][$name] = "Error message here"; } } return $result; }
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Validate field select box custom’ is closed to new replies.