2010-02-06 31 views
1

我已將Recaptcha與dJango集成。 dJango Snippet - Recaptchadjango:recaptcha:Firefox中的錯誤在IE和Chrome中工作:RecaptchaState錯誤

這顯示網頁的看法是 - 從baseapp.recaptcha進口驗證碼

def showHome(request):  
    if(request.user.is_authenticated()):  
     tempEmail = request.session.get('id')  
     return render_to_response('logreg/login-register.html', {'emailFromForm':tempEmail}, context_instance=RequestContext(request));  
    else:  
     request.session.set_test_cookie()  
     form = RegistrationForm()  
     loginForm = LoginForm()  
     html_captcha = captcha.displayhtml(settings.RECAPTCHA_PUB_KEY)  
     print "Captcha HTML is : %s" % html_captcha  
     return render_to_response('logreg/login-register.html', {'form': form, 'loginForm':loginForm, 'html_captcha':html_captcha}) ` 

這裏是HTML代碼 -

<div id="register-dialog" title="Register yourself">  
    <p id="validateTips">All form fields are required.</p>  
    {% if error %}  
    {{ error }}  
    {% endif %}  
    <form name="registrationForm" action="registerUser/" method="post">  
     {{ form.as_p }}  
     {{ html_captcha }}  
    </form>  
</div> 

它在IE瀏覽器&的偉大工程,但Firefox在recaptcha的451行顯示了一個例外。 這是在該行的代碼var $ST = RecaptchaState;

任何想法感謝!

注意:Firefox版本 - 3.6; IE - 8; Chrome - 4.0

+0

你可以發佈生成的HTML/JavaScript?這就是Firefox拋出錯誤的原因。 – scunliffe 2010-02-06 04:22:31

+0

從螢火蟲它表明,沒有其他代碼生成。這讓我直接在recaptcha.js的這一行。 這有點令人困惑。 我不確定FF加載代碼的順序是什麼,在其他任何事情之前下載js都是問題。只是猜測。 – PlanetUnknown 2010-02-06 14:16:42

回答

0

下面是我如何解決它。

我想我的驗證碼顯示在jqueryui對話框內,也許這是FF的問題。 (爲什麼?我不知道。) 因此,不要將文本從django靜態放置或寫出來。 我使用了ajax api並在對話框上的open事件中插入了recaptcha。

下面是示例代碼,以防有人在同一個問題上絆倒。

代碼幾乎類似什麼是對reCaptcha api site

$("#register-dialog").dialog({  
    buttons:{ 
    },  
    open: function() { 
    Recaptcha.create("41x39....", 
     "recaptcha_div", { 
     theme: "red", 
     callback: Recaptcha.focus_response_field 
     }); 

,並改變了形式的標籤是如此 -

<form name="registrationForm" action="registerUser/" method="post">  
    {{ form.as_p }}  
    <div id="recaptcha_div"></div>  
</form> 

是的,包括ajax.js -

<script type="text/javascript" src="http://api.recaptcha.net/js/recaptcha_ajax.js"> 
    </script> 
相關問題