Skip to content

Instantly share code, notes, and snippets.

@ammaridris
Last active February 14, 2016 05:18
Show Gist options
  • Save ammaridris/ea67fe8afa25eb451b44 to your computer and use it in GitHub Desktop.
Save ammaridris/ea67fe8afa25eb451b44 to your computer and use it in GitHub Desktop.
Borang Maklum Balas dengan Google reCAPTCHA 2
<?php
//boleh download di https://code.google.com/archive/p/recaptcha/downloads
//atau https://gist.github.com/ammaridris/94ac9db2ec6b50f3e571
require_once('recaptchalib.php');
//Kena generate ikut domain https://www.google.com/recaptcha/admin#createsite
$secret = "6Ld0OhgTAAAAADe872-FO9Vhcj5wLi9dYFZ2Pqcq";
$response = null;
$reCaptcha = new ReCaptcha($secret);
$act = $_REQUEST['act'];
$nama = $_REQUEST['nama'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$mesej = $_REQUEST['mesej'];
$mesej = stripcslashes($mesej);
$message = "Nama: $nama
E.Mail: $email
No. Telefon: $phone
Maklum Balas: $mesej";
$from = "From: $email";
if($act=="h") {
if(empty($nama)) {$style_nama="uk-form-danger";}
if(empty($email)) {$style_email="uk-form-danger";}
if(empty($mesej)) {$style_mesej="uk-form-danger";}
}
// if submitted check response
if($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$_POST["g-recaptcha-response"]
);
}
if($response != null && $response->success) {
//if berjaya
//echo "yes";
$berjaya = 1;
mail("alamat.emel.anda@gmail.com", "Maklum Balas Web", $message, $from);
} else {
//if tak berjaya
//$berjaya = 0;
}
?>
<script src='https://www.google.com/recaptcha/api.js?hl=ms'></script>
<?php if(!$berjaya) { ?>
<form name="hubungikami" method="post">
<div>
<label for="nama">Nama</label>
<div><input id="nama" name="nama" type="text" value="<?php echo $nama; ?>" required></div>
</div>
<div>
<label for="email">Email</label>
<div><input id="email" name="email" type="email" value="<?php echo $email; ?>" required></div>
</div>
<div>
<label for="phone">No. Telefon</label>
<div><input id="phone" name="phone" type="text" value="<?php echo $phone; ?>" class="uk-form-medium uk-form-width-large"></div>
</div>
<div>
<label for="mesej">Maklum Balas</label>
<div><textarea id="mesej" name="mesej" rows="7" cols="50" required><?php echo $mesej; ?></textarea></div>
</div>
<div>
<div><div class="g-recaptcha" data-sitekey="6Lci0BQTAAAAAAkaITwAUshloBSx9_zbXiZtCXe_"></div></div>
</div>
<div>
<label for=""></label>
<div><button class="uk-button uk-button-success" type="submit">Hantar</button> <button class="uk-button" type="reset">Reset</button></div>
</div>
<input name="act" type="hidden" value="h">
</form>
<?php } else { ?>
Terima kasih di atas maklum balas anda.
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment