Jump to content

Recommended Posts

I am a neophite to php.

I have a form that I need to ad reCaptcha to and when successful redirect to a Thank You page.

If I replace the header line below with an echo message, that works.

If I put the header line back in the code, I get the header error message.

 

What I would like to do when the reCaptcha is successful is to redirect visitors to an already created Thank you page, and

not just a Thank you message that appears below the reCaptcha.

 

I have read your HEADER ERRORS - READ HERE BEFORE POSTING THEM several times about putting the php in the header of the html

page, but still not sure how to actually do this since I really don't know php.

 

If I try to insert the code in the if valid area with the header, I of course get the header error you talk about here.

"Warning: Cannot modify header information - headers already sent by

(output started at /home/saturn/public_html/newsform4.php:10) in /home/mywebsite/public_html/form.php on line 55"

 

I have spent several days getting to this point and have tried several things, but nothing has worked.

Thank you in advance for your help.

Peggy Dixon   

 

Here is the form page code with the reCaptcha in itRe...

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>News Form</title>

</head>

<body>

<form method="post" action="">

<label for="firstname">First Name:</label>

<input type="text" name="firstname" id="firstname" /><br />

<label for="lastname"><strong>Last Name:</strong></label>

<input type="text" name="lastname" id="lastname" /><br />

<label for="orgname"><strong>Organization Name:</strong></label>

<input type="text" name="orgname" id="orgname" /><br />

<label for="address1"><strong>Address 1:</strong></label>

<input type="text" name="address1" id="address1" /><br />

           

<!--put the following script and noscript in the spot where you want the recaptcha to appear and this puts the captcha where you want it to appear on your page -->

<script type="text/javascript"

  src="http://api.recaptcha.net/challenge?k=<public code from the reCaptcha site >">

</script>

<noscript>

  <iframe src="http://api.recaptcha.net/noscript?k=<private code from the reCaptcha site >"

        width="350" frameborder="0"></iframe><br>

  <textarea name="recaptcha_challenge_field" rows="3" cols="40">

  </textarea>

  <input type="hidden" name="recaptcha_response_field"

      value="manual_challenge">

</noscript>

 

<?php

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey

$publickey = "public code from the reCaptcha site ";

$privatekey = "private code from the reCaptcha site ";

# the response from reCAPTCHA

$resp = null;

# the error code from reCAPTCHA, if any

$error = null;

# was there a reCAPTCHA response?

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) {             

$firstname = $_REQUEST['firstname'] ;

$lastname = $_REQUEST['lastname'] ;

$orgname = $_REQUEST['orgname'] ;

$address1 = $_REQUEST['address1'] ;

mail( "info@mywebsite.com", "Feedback Form Results",

"Organization: $orgname

\nAddress: $address1",

"From: $firstname $lastname <$email>");

header ( "Location: http://www.mywebsite.com/thanks.html");

}

else {# set the error code so that we can display it

$error = $resp->error;

}

}

echo recaptcha_get_html($publickey, $error);

?><br />

<label><input name="submit" type="submit" id="submit" value="Submit" /></label>

</form>

</body>

</html>

 

Okay see all that HTML at the start of the page! thats not allowed

try this

<?php
require_once('recaptchalib.php');
// Get a key from http://recaptcha.net/api/getkey
$publickey = "public code from the reCaptcha site ";
$privatekey = "private code from the reCaptcha site ";
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
# was there a reCAPTCHA response?
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) {               
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$orgname = $_REQUEST['orgname'] ;
$address1 = $_REQUEST['address1'] ;
mail( "info@mywebsite.com", "Feedback Form Results",
"Organization: $orgname
\nAddress: $address1",
"From: $firstname $lastname <$email>");
header ( "Location: http://www.mywebsite.com/thanks.html");
}
else {# set the error code so that we can display it
$error = $resp->error;
}
}
$reCAP = recaptcha_get_html($publickey, $error);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>News Form</title>
</head>
<body>
<form method="post" action="">
   <label for="firstname">First Name:</label>
      <input type="text" name="firstname" id="firstname" /><br />
   <label for="lastname"><strong>Last Name:</strong></label>
      <input type="text" name="lastname" id="lastname" /><br />
   <label for="orgname"><strong>Organization Name:</strong></label>
      <input type="text" name="orgname" id="orgname" /><br />
   <label for="address1"><strong>Address 1:</strong></label>
      <input type="text" name="address1" id="address1" /><br />
                
<!--put the following script and noscript in the spot where you want the recaptcha to appear and this puts the captcha where you want it to appear on your page -->
<script type="text/javascript"
   src="http://api.recaptcha.net/challenge?k=<public code from the reCaptcha site >">
</script>
<noscript>
   <iframe src="http://api.recaptcha.net/noscript?k=<private code from the reCaptcha site >"
        width="350" frameborder="0"></iframe><br>
   <textarea name="recaptcha_challenge_field" rows="3" cols="40">
   </textarea>
   <input type="hidden" name="recaptcha_response_field"
       value="manual_challenge">
</noscript>
<?php echo $reCAP;?>
<br />
      <label><input name="submit" type="submit" id="submit" value="Submit" /></label>
</form>
</body>
</html>

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.