custom validation for custom select
-
i have this custom form 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 = "<select class='form-control' required name='" . $tag['name'] . "' id='" . $tag['name'] . "' onchange='document.getElementById(\"" . $tag['name'] . "\").value=this.value;'> <option disabled value=\"\" selected hidden>Termin ausw?hlen:</option>"; foreach ( $events as $event ) { $output .= '<option value="' . $event->EventStartDate . $event->post_title . '">' . custom_kml_event_schedule_format( $event ) . $event->post_title . '</option>'; } // close foreach $output .= "</select>"; return $output; } // close function
…which produces the following dropdown.
<select class='form-control' required name='kml_probetraining_termine' id='kml_probetraining_termine' onchange='document.getElementById("kml_probetraining_termine").value=this.value;'> <option disabled value="" selected hidden>Termin ausw?hlen:</option><option value="Probetraining - Test">20.Oktober.2020 von 18:00 bis 19:00 |Probetraining - Test</option></select
so far so good, but i want to add cf7 validation to make this slelect a required field, as it seems the html5 required tag does not work with cf7.
any hints how to do it, i looked at the code of the cf7 select module but still can not figure out how to implement this.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘custom validation for custom select’ is closed to new replies.