#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Using Recaptcha on php, On Success Post Data To New Form


    Hi
    I'm new to php, i've been struggling for 2 days to write a simple code with recaptcha. My requirements is
    i have a registration form (reg.php) with 20 fields on it after all the required information is filled in the form data is submitted to Create Account page (CreateAccount.php).

    I placed a recaptcha control on the first page (reg.php) to secure the form from bots. I'm doing some javascript validation on the client side for required fields, and finally validating if correct recaptcha code is entered on the server side. That means the form is submitted to itself first for recaptcha validation, after the code is valid i want to resubmit the data to Account Creation page. i don't know how to do this. the CreateAccount.php has got a complex logic so i can not move it to the same reg.php page.

    i tried the following but with no luck...

    if ($_POST["recaptcha_response_field"]) {
    $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);

    if ($resp->is_valid) {
    //redirect to AccountCreation.php
    header("Location: AccountCreation.php");

    } else {
    $error = $resp->error;
    }
    }

    please help me how this is done is php. Is there any other way of doing it simply...
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0
    [PHPNET=""]require_once('recaptchalib.php');
    $privatekey = "<key>";
    $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 {

    $variable = $_POST[.....]

    /* fill in the rest of the processing and HTML here */

    }
    [/PHPNET]


    The above code is from my user registration page. you need to read the data in if it passes the recaptcha check, and use that form/php script to process the form and display any html content.
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    You can't perform a redirect of POST data.

    You could load the post data into a session variable, then redirect to CreateAccount.php. You would need to modify CreateAccount.php so that it reads from the session variables instead of the post variables.

    It sounds like you also could just include CreateAccount.php instead.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo