Skip to content

Instantly share code, notes, and snippets.

@isralduke
Last active November 23, 2015 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 = "recipient@email.com";
$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