使用ExtJS需要注册表单中的验证码字段

时间:2014-05-07 13:30:20

标签: extjs captcha extjs4.2

我正在使用ExtJS 4.2,我无法在注册表单中获取验证码字段。能够 有谁建议解决方案?

1 个答案:

答案 0 :(得分:0)

我使用谷歌recpatcha。我会在下面粘贴我的客户端代码。你需要自己做服务器端。你需要包括谷歌recaptcha库,并在你的表单上有一个面板,如下所示。然后,当您提交时,谷歌价值会上升,需要进行验证。

ExtJS的:

            {
                xtype: 'panel',
                border: false,
                height: 150,
                html: '<div id="recaptcha">Captcha Control From Google. This should be replaced by image by google</div>',
                itemId: 'reCaptcha',
                margin: '0 0 0 105'
            }

JavaScript提交点击事件

var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Creating New Account..."});
myMask.show();

localValues.recaptchaChallengeField = Recaptcha.get_challenge();
localValues.recaptchaResponseField =Recaptcha.get_response();

Ext.Ajax.on('requestexception', function (conn, response, options) {
myMask.hide();
if (response.status != 200) {
    var errorData = Ext.JSON.decode(response.responseText);


    Ext.MessageBox.show({
        title: 'Error Message',
        msg: errorData.message,
        icon: Ext.MessageBox.ERROR,
        buttons: Ext.Msg.OK
    });
    Ext.Msg.alert('Creating User Failed',errorData.message);
}
});

Ext.Ajax.request({
url:'/rpc/Account/CreateUser',
actionMethods:'POST',
scope:this,
params: localValues,
success: function(r, o) {
    myMask.hide();
    var retData = Ext.JSON.decode(r.responseText);


    } else {
        tabPanel.setActiveTab(tabPanel.getTabIdByName('AttendeeAfterLoginConf'));
    }

},
failure: function(r,o) {
     myMask.hide();
    // handled in exception now
    //debugger;
    //Ext.Msg.alert('Creating User Failed','');
}
});