Jump to content

help submitting a form


nobodyk

Recommended Posts

So I have this recapcha form and it's working perfectly. The only problem is that after it detects that the form was entered correctly it doesn't submit the form.

 

Here's the code:

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

//console.log( html );
if(html == "success") {
	//Add the Action to the Form
	$("form").attr("action", "contact2.php");
	//Indicate a Successful Captcha
	$("#captchaStatus").html("Success!");
	// Uncomment the following line in your application
	return true;
} else {
	$("#captchaStatus").html("The security code you entered did not match. Please try again.");
	Recaptcha.reload();
	return false;
}
}

<form action="contact2.php" method="post">
//stuff here
</form>

So this is the simplified version. Everything works, but I don't know excatly how I should use:

 $("form").attr("action", "contact2.php")

 

Is it used correctly?

Link to comment
Share on other sites

Personally, rather that wait until form validation is finished before adding the action to the form, I'd have it there, hide the submit button at the start, and use jQuerys .show() to display it once the form passes muster. 

 

You already have a <form> with contact2.php as the action--why are you trying to add it in as part of jQuery .ajax()?

 

Do you mean by "the form is working" that the ajax is working as expected?

 

Link to comment
Share on other sites

Well the ajax is working as expected, but I wanted to submit the form once it passes the validation. This is once of those script that uses recapcha and once the user enter the right code, then the form submits. recapcha is working perfectly. But once the user enters the right recapcha code it tells them "Success!", but nothing happens...and this is where I want for the form to be submitted. Having two submit buttons is kinda weird.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.