views:

61

answers:

2

Hi,

I have a php script which uses the following line to submit a form :

<form action = "javascript:void(null);" onsubmit = "load_ajax();" name = "myform">

Now, to protect bots from misusing the form I want to implement reCAPTCHA as described here :

http://www.darksideofthecarton.com/2008/12/15/validating-recaptcha-with-jquery-and-ajax/

The reCAPTCHA logic is working fine displaying verification Success/Fail message but the form is not getting submitted. Here is the code I am using to implement reCAPTCHA :

<form action = "javascript:void(null);" onsubmit = "return validateCaptcha()" name = "myform">

Validation part which I am using to call my load_ajax() function (which denotes successful form submission) :

    function validateCaptcha()
{
    challengeField = $("input#recaptcha_challenge_field").val();
    responseField = $("input#recaptcha_response_field").val();
    //alert(challengeField);
    //alert(responseField);
    //return false;
    var html = $.ajax({
    type: "POST",
    url: "ajax.recaptcha.php",
    data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
    async: false
    }).responseText;

    if(html == "success")
    {
        $("#captchaStatus").html("Success. Submitting form.");
        return false;
        // Uncomment the following line in your application
        load_ajax();
        return true;
    }
    else
    {
        $("#captchaStatus").html("Image verification failed, Pls. enter the image verification code correctly.");
        Recaptcha.reload();
        return false;
    }
}
</script>

I am not a php/javascript expert so help is needed.

Thanks

A: 

Your form is not submitted because you don't do anything after validation. Put an action in your form.action property and call it using jquery when validateCaptcha is true.

Spilarix
Thanks for replying, I tried the following : <form action = "javascript:load_ajax();" onsubmit = "return validateCaptcha()" name = "myform"> but it's not working, as I said am still learning javascript/php
A: 

The error was in this line inside validation routine (was returning false preventing form action routine) :

$("#captchaStatus").html("Success. Submitting form."); return false;