Steve
Steve

Reputation: 31

integrating reCaptcha into a form'a action to a coldfusion .cfm

I'm trying to help a friend modify some old html code to eliminate spam from being passed from the web form to the coldfusion function. Basically, the web form calls action=add_to_data.cfm. The friend wants to integrate recaptcha to cut down on spam going through the form. I've gotten that part to work and complete the reCaptcha verification. The problem is that I can't figure out how to call the coldfusion "add_to_data.cfm' action and pass along the form's data. There are plenty of recaptcha examples showing an exaple using action=mailer.php, but I need to send the form's data to coldfusion -- "add_to_data.cfm.

the original form:

<form method="post" action="add_to_data.CFm">
 ....blah, blah, blah ... form contents ...

<input type="submit" value="Please add to my Data />
<form>

Now, with guidance from a google developers reCaptcha turtorial, instead of going straight to "add_to_data.CFm," the only way that I can figure out how to validate the reCaptcha is to change the form action from "add_to_data.CFm" to an 'action' to newly created "verify_recaptcha.php" so that recaptcha can be validated.

<form method="post" action="verify_recaptcha.php">
 ...original form contents ...
        <?php
          require_once('recaptchalib.php');
          $publickey = "your_public_key_goes_here";
          echo recaptcha_get_html($publickey);
        ?>
        <input type="submit" />
<form>

This example is straight from google developers web pages for recpatcha validation with verify_recaptcha.php

<?php
  require_once('recaptchalib.php');
  $privatekey = "your_private_key_goes_here";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

    if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
       die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");

     } else {
     // Your code here to handle a successful verification  

     *** this is where I need gather he form outputs and call add_to_data.CFM
     ***  but HOW??

     }
     ?>

So my QUESTION is how to send the 'data' to add_to_data.CFm??

I know that inside of the 'else' section above, that I can get the form variables like this:

$name = $_POST['yourname'];
$email = $_POST['email'];
$data = $_POST['data'];
$comments = $_POST['comments'];
$formsub = $_POST['Submit']; 

so the QUESTION is: HOW do I complete the form submit action to "add_to_data.CFM"??

thanks in advance

Upvotes: 3

Views: 1512

Answers (1)

Busches
Busches

Reputation: 1964

The easiest way to fix your problem is to have CF validate the reCaptcha. You can find many tutorials on google, the one that I've used in the past is the below link.

http://recaptcha.riaforge.org/

This is a tag based implementation that I based my last implementation off of, so this does work.

Otherwise if you really want to have php send the data to CF, the easiest way that comes to my mind is to have php auto-submit a form to pass the data back to CF. You'll need some extra security to ensure no one is hijacking the form or trying to bypass the reCaptchadoing that though. I'd highly recommend doing the validation in all CF.

Upvotes: 1

Related Questions