tpsilver10 Posted May 8, 2007 Share Posted May 8, 2007 G'day, I'm trying to implement a CAPTCHA field into my existing form, with limited success so far. I've been able to get it to tell me that the code is wrong. I've also been able to get it to tell me I'm right, but when I need to process the form into a database...that's where it fails. If someone could take a look at the code that'd be bloody unreal. <?php session_start(); require("../africaforms/global/library.php"); if( isset($_POST['submit'])) { if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) { letsgo(); unset($_SESSION['security_code']); } else { echo 'WRONG!'; } } else { function letsgo() { // check we're receiving something if (empty($_POST)) ft_output_message("no_post_vars"); // check there's a form ID included else if (empty($_POST['form_tools_form_id'])) ft_output_message("no_form_id"); // is this an initialization submission? else if (isset($_POST['form_tools_initialize_form'])) ft_initialize_form(); // otherwise, it's a regular form submission. Process it. else process_form(); } //the rest of the form [process_form();] ?> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/ Share on other sites More sharing options...
tpsilver10 Posted May 8, 2007 Author Share Posted May 8, 2007 No one? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248230 Share on other sites More sharing options...
tpsilver10 Posted May 8, 2007 Author Share Posted May 8, 2007 Please??? This is a killer of an issue. It has 9 views...can no one even look at it?? Quote Link to comment https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248418 Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 Correct me if I am wrong, but the function definition should be outside that else statement as if inside it will only get defined if the condition is true. That is one problem. Another one might possible be the else if. Remove that space and make it elseif. I would also probably add the curly braces { } to the if statements since you have soo many of them just to keep them in sync. Quote Link to comment https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248425 Share on other sites More sharing options...
tpsilver10 Posted May 8, 2007 Author Share Posted May 8, 2007 Correct me if I am wrong, but the function definition should be outside that else statement as if inside it will only get defined if the condition is true. That is one problem. Thanks for the reply mate. I'm not sure if that's a problem as such, because I only want the function to happen if the condition is true (in this case the correct security code was entered). I added the curly braces and changed the else if to elseif, but still no luck. Quote Link to comment https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248440 Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 The reason I pointed that out is because you call the function inside the if statement. When the definition is inside the else portion. Which contradicts itself. If you only want to use that function inside the if portion than define in there and not in the else. Quote Link to comment https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248458 Share on other sites More sharing options...
tpsilver10 Posted May 8, 2007 Author Share Posted May 8, 2007 Ahh yes I see. So if I tried something more like: <?php if( isset($_POST['submit'])) { if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) { letsgo(); unset($_SESSION['security_code']); } else { echo 'WRONG!'; } } else { exit() } function letsgo() { // check we're receiving something if (empty($_POST)) { ft_output_message("no_post_vars"); } // check there's a form ID included elseif (empty($_POST['form_tools_form_id'])) { ft_output_message("no_form_id"); } // is this an initialization submission? elseif (isset($_POST['form_tools_initialize_form'])) { ft_initialize_form(); } // otherwise, it's a regular form submission. Process it. else { process_form(); } ?> It doesn't work I know...but does that close of the else? Quote Link to comment https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248485 Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 Yes, you would also need an extra } after the process_form(); } to close off the function, but now you have the idea. Quote Link to comment https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248493 Share on other sites More sharing options...
tpsilver10 Posted May 8, 2007 Author Share Posted May 8, 2007 Okay cheers for that mate... Now I'm at <?php if( isset($_POST['submit'])) { if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) { letsgo(); unset($_SESSION['security_code']); } else { echo 'WRONG!'; } } else exit() { } function letsgo() { // check we're receiving something if (empty($_POST)) { ft_output_message("no_post_vars"); } // check there's a form ID included elseif (empty($_POST['form_tools_form_id'])) { ft_output_message("no_form_id"); } // is this an initialization submission? elseif (isset($_POST['form_tools_initialize_form'])) { ft_initialize_form(); } // otherwise, it's a regular form submission. Process it. else { process_form(); } } ?> But still no luck Quote Link to comment https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248505 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.