Php 无captcha错误处理的自定义登录

Php 无captcha错误处理的自定义登录,php,error-handling,recaptcha,Php,Error Handling,Recaptcha,我已经创建了一个自定义的登录页面,但是当验证码为空并且处理了long时,我试图将错误消息$error\u消息传递给$error\u msg 我正在使用两个wp插件,一个是无验证码recaptcha插件,另一个是客户端模板门户 下面是custom-login.php的完整代码 <?php class Ncr_Custom_Login_Captcha extends Ncr_No_Captcha_Recaptcha { public static function initiali

我已经创建了一个自定义的登录页面,但是当验证码为空并且处理了long时,我试图将错误消息$error\u消息传递给$error\u msg

我正在使用两个wp插件,一个是无验证码recaptcha插件,另一个是客户端模板门户

下面是custom-login.php的完整代码

<?php

class Ncr_Custom_Login_Captcha extends Ncr_No_Captcha_Recaptcha {

    public static function initialize() {

        // initialize if login is activated
        if ( isset(self::$plugin_options['captcha_login']) && self::$plugin_options['captcha_login'] == 'yes') {
            // add captcha header script to WordPress header
            add_action( 'wp_head', array( __CLASS__, 'header_script' ) );

            // adds the captcha to the custom login form
            add_action( 'custom_captcha_login', array( __CLASS__, 'display_captcha' ) );

            // authenticate the captcha answer
            add_action( 'custom_authenticate_user', array( __CLASS__, 'validate_captcha_custom_login' ), 10, 2 );
        }
    }

    /**
     * Verify the captcha answer
     *
     * @param $user string login username
     * @param $password string login password
     *
     * @return WP_Error|WP_user
     */

    public static function validate_captcha_custom_login( $user, $password ) {
        if ( ! isset( $_POST['g-recaptcha-response'] ) || ! self::captcha_verification() ) {}
        $error_msg .= 'I want to show this message';
        return false;
    }

}
下面是其他插件使用的登录表单模板页面

{if $action == 'login'}
    {if !empty($msg_ve)}
        <p class="message">{$msg_ve}</p>
    {/if}
    <form method="post" action="{if !empty($login_url)}{$login_url}{/if}" id="loginform" name="loginform">
        {if !empty($somefields)}{$somefields}{/if}
        {if !empty($error_msg)}
            <p class="message wpc_error">{$error_msg}</p>
        {/if}
        {if !empty($custom_login_error_msg)}
            <p class="message wpc_error">{$custom_login_error_msg}</p>
        {/if}
        <p>
            <label for="user_login">{if !empty($labels.username)}{$labels.username}{/if}<br>
            <input type="text" tabindex="10" size="20" value="" class="input" id="user_login" name="log"></label>
        </p>
        <p>
            <label for="user_pass">{if !empty($labels.password)}{$labels.password}{/if}<br>
            <input type="password" tabindex="20" size="20" value="" class="input" id="user_pass" name="pwd"></label>
        </p>
        {do_action( 'custom_captcha_login' )}
        <p class="forgetmenot"><label for="rememberme"><input type="checkbox" tabindex="90" value="forever" id="rememberme" name="rememberme"> {if !empty($labels.remember)}{$labels.remember}{/if}</label></p>
        <p class="submit">
            <label>
                <input type="submit" tabindex="100" value="Log In" class="button-primary" id="wp-submit" name="wp-submit">
                <input type="hidden" value="" name="redirect_to">
            </label>
        </p>

        {if isset($lostpassword_href) && !empty($lostpassword_href)}
        <p id="nav">
            <label>
                <a title="Password Lost and Found" href="{$lostpassword_href}">Lost your password?</a>
            </label>
        </p>
        {/if}
    </form>
{elseif $action == 'lostpassword' && isset($lostpassword_href) && !empty($lostpassword_href) }
    <form method="post" action="{if !empty($login_url)}{$login_url}{/if}" id="loginform" name="loginform">
        {if !empty($error_msg)}
            <p class="message wpc_error">{$error_msg}</p>
        {/if}
        <p>
            <label for="user_login">{if !empty($labels.email)}{$labels.email}{/if}<br>
            <input type="text" tabindex="10" size="35" value="" class="input" id="user_login" name="user_login"></label>
        </p>
        <p class="submit">
            <label>
                <input type="submit" tabindex="100" value="{if !empty($labels.get_new_password)}{$labels.get_new_password}{/if}" class="button button-primary button-large" id="wp-submit" name="wp-submit">
            </label>
        </p>
        <p id="nav">
            <label>
                <a title="Back to Login Page" href="{$login_href}">Remember your password?</a>
            </label>
        </p>
    </form>
{elseif ( $action == 'rp' || $action == 'resetpass' ) && !empty($lostpassword_href) }
    <form method="post" action="{if !empty($login_url)}{$login_url}{/if}" id="loginform" name="loginform">
        {if !empty($error_msg)}
            <p class="message wpc_error">{$error_msg}</p>
        {/if}
        {if !in_array($error_msg, $check_invalid)}
            <input type="hidden" id="user_login" value="{if !empty($user_login)}{$user_login}{/if}" autocomplete="off" />
            <p>
                <label for="pass1">{if !empty($labels.new_password)}{$labels.new_password}{/if}<br />
                <input type="password" name="pass1" id="pass1" class="input" size="35" value="" autocomplete="off" /></label>
            </p>
            <p>
                <label for="pass2">{if !empty($labels.confirm_new_password)}{$labels.confirm_new_password}{/if}<br />
                <input type="password" name="pass2" id="pass2" class="input" size="35" value="" autocomplete="off" /></label>
            </p>

            <div id="pass-strength-result">{if !empty($labels.strength_indicator)}{$labels.strength_indicator}{/if}</div>
            <p class="description indicator-hint">{if !empty($labels.hint_indicator)}{$labels.hint_indicator}{/if}</p>
            <br class="clear" />
            <p class="submit"><label><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="{if !empty($labels.reset_password)}{$labels.reset_password}{/if}" /></label>
            </p>
        </form>
    {/if}
{/if}

试试这个,这个对我有用

有效

if(validationfunctions failed)
{
$error_msg .= '<p class="error">I want to show this message</p>';
return false;
}

不要在函数内部设置错误消息

我试过一些方法,但似乎没有任何效果!isset$_POST['g-recaptcha-response']| |!self::captcha_验证{die;}否则{//Let User Pass return$User;}`您只需要传递错误消息??或者captha有任何问题吗?是的,如果失败,我似乎无法传递错误消息并停止验证。该页面是使用以下php表达式从WP模板页面构建运行的{if!empty$custom\u login\u error\u msg}

{echo$custom\u login\u error\u msg}

{/if}{echo$custom login\u error\u msg}导致模板加载失败,所以我不得不使用{$custom_login_error_msg}尝试了两个公共静态函数validate_captcha_custom_login$user,$password{if!isset$_POST['g-recaptcha-response']| |!self::captcha_verification{$error_msg.='

我想显示此消息

';return false;}---和---public static function validate_captcha_custom_login$user,$password{if!isset$_POST['g-recaptcha-response']| |!self::captcha_-verification{}$error| msg.='

我想显示此消息

';return false;}--两者似乎都没有显示错误消息这是在模板页面上的`{if!清空$custom\u login\u error\u msg}

{$custom\u login\u error\u msg}

{/if}`即使只是将

{$custom\u login\u error\u msg}

放入模板中并尝试处理验证,也只会显示核心模板

{$error\u msg}

是否显示其错误消息?
if(validationfunctions failed)
{
$error_msg .= '<p class="error">I want to show this message</p>';
return false;
}
if (!empty($error_msg)) {
echo $error_msg;
}