PHP 弹出警报

时间:2021-02-12 15:43:46

标签: javascript php

我在 WordPress 网站上使用 WPforms。我有两个复选框,您只能选中一个复选框。如果您选择两个,则警告您已超出允许的选择数量:1.

enter image description here

我希望将此作为 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 );
        }

0 个答案:

没有答案