I am using WPforms on a WordPress site. I have two checkboxes and you are only allowed to check one box. if you select two you get a warning you have exceeded the number of allowed selections: 1.
I would like this as a POPUP alert or warning. I searched the code and found the following
if ( $choice_limit > 0 && $count_choices > $choice_limit ) {
// Generating the error.$error = wpforms_setting( 'validation-check-limit', esc_html__( 'You have exceeded the number of allowed selections: {#}.', 'wpforms-lite' ) );
$error = str_replace( '{#}', $choice_limit, $error ); }
I tried this
if ( $choice_limit > 0 && $count_choices > $choice_limit ) {
// Generating the error.
$error = wpforms_setting( 'validation-check-limit', esc_html__( 'You have exceeded the number of allowed selections: {#}.', 'wpforms-lite' ) );
echo '<script>alert("You have exceeded the number of allowed selections: {#}.")</script>';
$error = str_replace( '{#}', $choice_limit, $error );
}
This is in class-settings-php
'validation-check-limit' => [
'id' => 'validation-check-limit',
'name' => esc_html__( 'Checkbox Selection Limit', 'wpforms-lite' ),
'type' => 'text',
'default' => esc_html__( 'You have exceeded the number of allowed selections: {#}.', 'wpforms-lite' ),
],
This is in class-frontend.php
'val_checklimit' => wpforms_setting( 'validation-check-limit', esc_html__( 'You have exceeded the number of allowed selections: {#}.', 'wpforms-lite' ) ),
And this is in the class-checkbox.php
if ( $choice_limit > 0 && $count_choices > $choice_limit ) {
// Generating the error.
$error = wpforms_setting( 'validation-check-limit', esc_html__( 'You have exceeded the number of allowed selections: {#}.', 'wpforms-lite' ) );
$error = str_replace( '{#}', $choice_limit, $error );
}
The above picture was only an example. I have 40 checkboxes. You are only allowed to select 4. If you select more than 4 I would like a noticeable popup. On some screens, you cannot see the warning as there are too many checkboxes.