Thomas08 Posted July 24, 2008 Share Posted July 24, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/ Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 looks like a dodgy image captcha... Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/#findComment-598456 Share on other sites More sharing options...
unkwntech Posted July 24, 2008 Share Posted July 24, 2008 You could add a javascript onClick to the button to submit the form. Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/#findComment-598480 Share on other sites More sharing options...
Thomas08 Posted July 24, 2008 Author Share Posted July 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/#findComment-598524 Share on other sites More sharing options...
Thomas08 Posted July 24, 2008 Author Share Posted July 24, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/#findComment-598527 Share on other sites More sharing options...
Thomas08 Posted July 28, 2008 Author Share Posted July 28, 2008 Can I rephrase the question, is there a way of telling a form to submit in php? Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/#findComment-601408 Share on other sites More sharing options...
LemonInflux Posted July 28, 2008 Share Posted July 28, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/#findComment-601414 Share on other sites More sharing options...
Thomas08 Posted July 28, 2008 Author Share Posted July 28, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/#findComment-601438 Share on other sites More sharing options...
TempleDMDKrazd Posted July 28, 2008 Share Posted July 28, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/#findComment-601539 Share on other sites More sharing options...
JonnoTheDev Posted July 28, 2008 Share Posted July 28, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/#findComment-601573 Share on other sites More sharing options...
Thomas08 Posted July 28, 2008 Author Share Posted July 28, 2008 Last 2 posts have given me something to think about, ill keep you updated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116380-submitting-variable-form-action/#findComment-601740 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.