custom validation message not showing
-
custom tag:
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_kml_probetraining_customfield' ); function wpcf7_add_form_tag_kml_probetraining_customfield() { wpcf7_add_form_tag( array('kml_probetraining_termine_select', 'kml_probetraining_termine_select*'), 'wpcf7_kml_probetraining_customfield_form_tag_handler', array( 'name-attr' => true ) ); } function wpcf7_kml_probetraining_customfield_form_tag_handler ( $tag ) { $tag = new WPCF7_FormTag( $tag ); if ( empty( $tag->name ) ) { return ''; } $events = tribe_get_events( array( 'posts_per_page' => -1, // 'start_date' => date( 'Y-m-d H:i:s' ), 'start_date' => 'now', 's' => "Probetraining" ) ); $output = ''; $output .= sprintf( '<span class="wpcf7-form-control-wrap" %s">', $tag->name ); $output .= sprintf( "<select name='" . $tag['name'] . "' id='" . $tag['name'] . "' class=\"wpcf7-form-control wpcf7-select wpcf7-validates-as-required\" aria-required=\"true\" aria-invalid=\"false\">", $tag->name ); $output .= sprintf( '<option value=\"\" selected disabled hidden>Termin ausw?hlen:</option>', $tag->name ); foreach ( $events as $event ) { $output .= sprintf( '<option value="' . $event->EventStartDate . $event->post_title .'">' . custom_kml_event_schedule_format( $event ) . $event->post_title . '</option>', $tag->name ); } // close foreach $output .= '</select>'; $output .= '</span>'; return $output; } // close function
custom filter:
add_filter( 'wpcf7_validate_kml_probetraining_termine_select', 'wpcf7_kml_probetraining_termine_select_validation_filter', 10, 2 ); add_filter( 'wpcf7_validate_kml_probetraining_termine_select*', 'wpcf7_kml_probetraining_termine_select_validation_filter', 10, 2 ); function wpcf7_kml_probetraining_termine_select_validation_filter( $result, $tag ) { $tag = new WPCF7_FormTag( $tag ); $name = $tag->name; if ( isset( $_POST[$name] ) && is_array( $_POST[$name] ) ) { foreach ( $_POST[$name] as $key => $value ) { if ( '' === $value ) { unset( $_POST[$name][$key] ); } } } $empty = ! isset( $_POST[$name] ) || empty( $_POST[$name] ) && '0' !== $_POST[$name]; if ( $tag->is_required() && $empty ) { $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); } return $result; }
validation works, but the validation error message is not shown. what needs to be added to make the message appear?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘custom validation message not showing’ is closed to new replies.