Jump to content

reCaptcha integration problems


iVazanity

Recommended Posts

Hello im very new to PHP and I got a problem with integrating reCaptcha into my Form. Step one worked pretty good but im failing on Step 2 which is: If your users send the form with integrated reCAPTCHA, you will receive among other things, a string containing the name "G-recaptcha-response". If you want to find out if Google has verified the user in question, send a POST request with the following parameters:

Secret (required) MY_SECRET_CODE Response (required) Value of 'g-recaptcha-response' remoteip The IP address of the end user

Heres my HTML Code:

<!DOCTYPE html>
<html >
  <head>
    <meta charset="UTF-8">
	<meta name="description" content="Kontaktieren Sie hier Mario Fracasso">
	<meta name="keywords" content="contact,kontakt,mario,fracasso,mariofracasso,schreiben,websites,offer">
	<meta name="author" content="Mario Fracasso">
		<title>Contact - Mario Fracasso</title>
			<link rel="stylesheet" href="css/style.css">
				<script src='https://www.google.com/recaptcha/api.js'></script>
  </head>

  <body>

    <div id="form-main">
  <div id="form-div">
	<h1>Contact - Mario Fracasso</h1>
	<hr>
    <form action="php/form_process.php" method="post" class="form" id="form1">
      
      <p class="name">
        <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="First Name, Last Name" id="name" />
      </p>
      
      <p class="email">
        <input name="email" type="email" class="validate[required,custom[email]] feedback-input" id="email" placeholder="Email" />
      </p>
      
      <p class="text">
        <textarea name="text" class="validate[required,length[6,300]] feedback-input" id="comment" placeholder="Message"></textarea>
      </p>
      
<div class="g-recaptcha" data-sitekey="MYCODE"></div>
<p>
      <div class="submit">
        <input type="submit" value="SEND" id="button-blue"/>
        <div class="ease"></div>
      </div>
    </form>
<footer>
<p>© Mario Fracasso</p>    
</footer>
  </div>
	</div>
  </body>
</html>

And heres my PHP Code:

<?php
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "MY_EMAIL";
 
    $email_subject = "Your email subject line";
 
     
 
     
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    // validation expected data exists
 
    if(!isset($_POST['name']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['text'])) {
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
     
 
    $name = $_POST['name']; // required
 
    $email_from = $_POST['email']; // required
 
 
    $text = $_POST['text']; // required
 
     
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$name)) {
 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
 
  }
 
  if(strlen($text) < 2) {
 
    $error_message .= 'The text you entered do not appear to be valid.<br />';
 
  }
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
     
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
     
 
    $email_message .= "First Name: ".clean_string($name)."\n";
 
 
    $email_message .= "Email: ".clean_string($email_from)."\n";
 
 
    $email_message .= "text: ".clean_string($text)."\n";
 
     
 
     
 
// create email headers
 
$headers = 'From: '.$email_from."\r\n".
 
'Reply-To: '.$email_from."\r\n" .
 
'X-Mailer: PHP/' . phpversion();
 
@mail($email_to, $email_subject, $email_message, $headers);  
 
?>
 
 
 
<!-- include your own success html here -->
 
 
 
Thank you for contacting us. We will be in touch with you very soon.
 
 
 
<?php
 
}
 
?>

So, heres my question: How do I implement this reCaptcha? Is there any solution? I hope you can help me - oh and hey, im sorry for my bad english.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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.