djkee Posted November 21, 2009 Share Posted November 21, 2009 I have this awesome ajax script that submits a form and give a success or fail response back but then i want to also include recaptcha in the form and its just horrible. I am stuck and i dont know where is the error in the script When i click submit the script wont even respond anymore Please Help me debug it. <html> <head> <script type="text/javascript"> var time_variable; function getXMLObject() //XML OBJECT { var xmlHttp = false; try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+ } catch (e2) { xmlHttp = false // No Browser accepts the XMLHTTP Object then false } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers } return xmlHttp; // Mandatory Statement returning the ajax object created } var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object function ajaxFunction() { var getdate = new Date(); //Used to prevent caching during ajax call if(xmlhttp) { var gamename = document.getElementById("gamename"); var gamecategory = document.getElementById("gamecategory"); var gamedescription = document.getElementById("gamedescription"); var uploadermail = document.getElementById("uploadermail"); var uploadedfile = document.getElementById("uploadedfile"); var thumbnailurl = document.getElementById("thumbnailurl"); challengeField = $("input#recaptcha_challenge_field").val(); responseField = $("input#recaptcha_response_field").val(); xmlhttp.open("POST","http://*removed*/uploader.php",true); //calling addreview.php using POST method xmlhttp.onreadystatechange = handleServerResponse; xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send("gamename=" + gamename.value + "&gamecategory=" + gamecategory.value + "&gamedescription=" + gamedescription.value + "&uploadermail=" + uploadermail.value + "&uploadedfile=" + uploadedfile.value + "&thumbnailurl=" + thumbnailurl.value + "&recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField); //Posting fields to PHP File } } function handleServerResponse() { if (xmlhttp.readyState == 4) { if(xmlhttp.status == 200) { document.getElementById("message").innerHTML=xmlhttp.responseText; //Update the HTML Form element } else { alert("Error during AJAX call. Please try again"); } } } </script> </head> <body> <div id="message" name="message"><div> Name of the game: <input id="gamename" style="width: 200px; height: 25px;" type="text" name="gamename" onKeyDown="limitText(this.form.limitedtextfield,this.form.countdown,45);" onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,45);" maxlength="45"/><br /><br /> Game Category: <input id="gamecategory" style="width: 200px; height: 25px;" type="text" name="gamecategory" onKeyDown="limitText(this.form.limitedtextfield,this.form.countdown,45);" onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,45);" maxlength="45" /><br /><br /> Game Description: <input id="gamedescription" style="width: 200px; height: 105px;" type="text" name="gamedescription" onKeyDown="limitText(this.form.limitedtextfield,this.form.countdown,200);" onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,200);" maxlength="200" /><br /><br /> Your real email: <input id="uploadermail" style="width: 200px; height: 25px;" type="text" name="uploadermail" onKeyDown="limitText(this.form.limitedtextfield,this.form.countdown,45);" onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,45);" maxlength="45" /><br /><br /> <!--<input type="hidden" name="MAX_FILE_SIZE" value="100000" />--> Choose the game to upload: <input id="uploadedfile" name="uploadedfile" type="file" /><br /><br /> Url to the game thumbnail: <input id="thumbnailurl" style="width: 200px; height: 25px;" type="text" name="thumbnailurl" onKeyDown="limitText(this.form.limitedtextfield,this.form.countdown,65);" onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,65);" maxlength="65" /><br /><br /> <?php require_once('/home/*removed*/public_html/recaptchalib.php'); $publickey = "6LcMrwMAAAAAAFigtAy6LJ7gVsQwP6zv6K9CUA3E"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> <br><br><input type="button" value="Upload Game" onclick="ajaxFunction();" /> </body> </html> Thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/182351-ajax-submit-form-and-recaptcha-help/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.