Jump to content

Recommended Posts

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
    }
?> 

Link to comment
https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248425
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248440
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248458
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248485
Share on other sites

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  :(

Link to comment
https://forums.phpfreaks.com/topic/50501-php-form-with-captcha/#findComment-248505
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.