我在 WordPress 网站上使用 WPforms。我有两个复选框,您只能选中一个复选框。如果您选择两个,则警告您已超出允许的选择数量:1.
我希望将此作为 POPUP 警报或警告。我搜索了代码,发现了以下内容
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 ); }
我试过了
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 );
}
这是在 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' ),
],
这是在 class-frontend.php 中
'val_checklimit' => wpforms_setting( 'validation-check-limit', esc_html__( 'You have exceeded the number of allowed selections: {#}.', 'wpforms-lite' ) ),
这是在 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 );
}