Skip to content

Instantly share code, notes, and snippets.

@abel-masila
Created May 31, 2017 07:31
Show Gist options
  • Save abel-masila/d341f4be332e91b388e276a288a4c58f to your computer and use it in GitHub Desktop.
Save abel-masila/d341f4be332e91b388e276a288a4c58f to your computer and use it in GitHub Desktop.
<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="col-sm-6 col-xs-12">
<div class="row">
<form id="comment_form" action="form.php" method="post" data-success="Thanks for your enquiry, we'll be in touch shortly." data-error="Please fill in all fields correctly.">
<div class="col-sm-6 col-xs-12"> <label>Your Name:</label> <input type="text" name="Name" class="validate-required"> </div>
<div class="col-sm-6 col-xs-12"> <label>Email Address:</label> <input type="email" name="Email" class="validate-required validate-email"> </div>
<div class="col-sm-12 col-xs-12"> <label>comment:</label> <textarea rows="4" name="comment" class="validate-required"></textarea> </div>
<div class="g-recaptcha" data-sitekey="6LfwdCMUAAAAAAj9Pyd4Y_-n2fo1WvZrqNrZis10"></div>
<?php
session_start();
if(isset($_SESSION['message'])){
echo "<h4 class=\"alert alert-success alert-dismissible\" role=\"alert\">" .$_SESSION['message']."</h4>";
unset($_SESSION['message']);
}?>
<div class="col-sm-5 col-md-4 col-xs-6"> <input type="submit" name="submit" value="Send Enquiry" class="btn btn--primary type--uppercase"> </div>
</form>
</div>
</div>
<?php
session_start();
if(isset($_POST['submit'])){
$email;$comment;$captcha;
if(isset($_POST['Name'])){
$email=$_POST['Name'];
}if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['comment'])){
$email=$_POST['comment'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
$_SESSION['message']="please check the the captcha form";
header('Location: script.php');
}
$secretKey = "6LfwdCMUAAAAAFyUc2wVkdCjDvGjzrrCpm5heb-I";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are spammer ! Get the @$%K out</h2>';
} else {
echo '<h2>Thanks for posting comment.</h2>';
}
} else {
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment