diff --git a/modules/checkbox.php b/modules/checkbox.php index b962652c..aca6f183 100644 --- a/modules/checkbox.php +++ b/modules/checkbox.php @@ -196,16 +196,30 @@ function wpcf7_checkbox_form_tag_handler( $tag ) { function wpcf7_swv_add_checkbox_rules( $schema, $contact_form ) { $tags = $contact_form->scan_form_tags( array( - 'type' => array( 'checkbox*', 'radio' ), + 'basetype' => array( 'checkbox', 'radio' ), ) ); foreach ( $tags as $tag ) { - $schema->add_rule( - wpcf7_swv_create_rule( 'required', array( - 'field' => $tag->name, - 'error' => wpcf7_get_message( 'invalid_required' ), - ) ) - ); + if ( $tag->is_required() or 'radio' === $tag->type ) { + $schema->add_rule( + wpcf7_swv_create_rule( 'required', array( + 'field' => $tag->name, + 'error' => wpcf7_get_message( 'invalid_required' ), + ) ) + ); + } + + if ( 'radio' === $tag->type or $tag->has_option( 'exclusive' ) ) { + $schema->add_rule( + wpcf7_swv_create_rule( 'maxitems', array( + 'field' => $tag->name, + 'threshold' => 1, + 'error' => $contact_form->filter_message( + __( "Too many items are selected.", 'contact-form-7' ) + ), + ) ) + ); + } } }