Jump to content

Recommended Posts

Hello, im trying to integrate a captcha code with a form handler script (called tectite)

 

I have the captcha within a form, the handling code of which is inline with the page, the following if statement checks wether the captcha verification code was correct.

 

if(isChallengeAccepted($_POST[$CHALLENGE_FIELD_PARAM_NAME]) === FALSE) {    //if the wrong captcha code was entered

        $resultMessage = "The entered verification code was not correct.";  //display error message on form

$formaction = "#"; //$formaction is a variable on the forms action, in this case it shouldnt go anywhere

 

}

                else {  //or if code was correct..

$formaction = "Mailer.php";  //the form should action submit to the form handler

}

 

Here is the action variable within the html

 

<form action="<?php echo $formaction?>"

 

However, in the case that the code was entered correctly, all it does is set the action to Mailer.php but does not submit it, clicking submit a second time gets the desired effect. How can I get the form to submit providing the code was entered correctly and the submit button was clicked once?

 

Thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/
Share on other sites

You could add a javascript onClick to the button to submit the form.

 

yeah I tried this

 

<script language="javascript">
<!--
function submitForm()
{
    document.form.submit(); 
    document.form.submit();	 
}
-->
</script>

 

and but the function on the onclick of the submit button, but that didnt work.

I forgot to use code tags  :-X

 

Hello, im trying to integrate a captcha code with a form handler script (called tectite)

 

I have the captcha within a form, the handling code of which is inline with the page, the following if statement checks wether the captcha verification code was correct.

 

if(isChallengeAccepted($_POST[$CHALLENGE_FIELD_PARAM_NAME]) === FALSE) {     //if the wrong captcha code was entered
	        $resultMessage = "The entered verification code was not correct.";  //display error message on form
		$formaction = "#"; //$formaction is a variable on the forms action, in this case it shouldnt go anywhere		

	}
                else {  //or if code was correct..	 		
		$formaction = "Mailer.php";  //the form should action submit to the form handler			
	}

 

Here is the action variable within the html

 

<form action="<?php echo $formaction?>"

 

However, in the case that the code was entered correctly, all it does is set the action to Mailer.php but does not submit it, clicking submit a second time gets the desired effect. How can I get the form to submit providing the code was entered correctly and the submit button was clicked once?

 

Thanks for any help

No. Would you need to? <input type="submit" value="submit" /> works for me.

 

----------------

Now playing: Enter Shikari - Today Won't Go Down In History

via FoxyTunes

 

The submit button is only setting the correct action variable on the form and not sending.

the reason its not sending is because when you first submit the action is blank...but after the submit the action now has "Mailer.php". the way you're doing it there has to be a better way than that. why are you hiding "Mailer.php" for?

This is certainly the wrong approach to implement captcha. The form action should not be set after captcha validation.

Your form fields should be validated along with the captcha input in the same instance so in psuedo code:

 

// form submitted, validate fields

// 1. user entered name?

// 2. user entered email address?

// 3. captcha valid?

// 4. errors found

// 4a. yes, display errors and reload form generating new captcha, restore user entered values into form fields

// 4b. no, save form data and redirect user to success page

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.