Skip to content

Instantly share code, notes, and snippets.

@isralduke
Last active November 23, 2015 18:35
Show Gist options
  • Save isralduke/e02fc44da256ca42030a to your computer and use it in GitHub Desktop.
Save isralduke/e02fc44da256ca42030a to your computer and use it in GitHub Desktop.
Spam Reduction in Simple Forms
<?php
$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
$field3 = $_POST['field3'];
$field4 = $_POST['field4'];
$field5 = $_POST['field5'];
$formcontent = "FieldOne: $field1 \n FieldTwo: $field2 \n FieldThree: $field3 \n FieldFour $field4 \n FieldFive: $field5";
$recipient = "[email protected]";
$subject = "This is the Subject";
$mailheader = "From: $email \r\n";
mail( $recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thanks.";
?>
// this file in intentionally left blank
$(document).ready( function()
{
// feedback after form submissio
function confirm() {
$("#form").get(0).reset();
// a <p> tag or something with a thank you message
$('.confirmation').slideToggle('fast');
}
// runs the check to detect if hidden field has been changed
$('#submitter').click(function()
{
if ( $('#hiddenField').val() !== "" )
{
$('#form').attr("action","spam.php");
// AJAX Form Submitter can be found at https://github.com/malsup/form
$('#form').ajaxForm(function() {
confirm();
});
}
else {
$('#form').attr("action","notSpam.php");
// AJAX Form Submitter can be found at https://github.com/malsup/form
$('#form').ajaxForm(function() {
confirm();
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment