Forum Moderators: coopster
I'm fairly new to the PHP scene, but I've been in web development for (what feels like) forever.
I'm having a strange thing happen. I've developed six separate application forms for various subventions, and they are working beautifully. The problem is that I'm getting multiple blank forms sent to the server over and over. If one form gets sent, then I inevitably get all of the forms sent to me (all blank) within a few hours of the initial form submission. I was reading in the archives that it might have something to do with the fact that all of my form fields are named the same, and so are all being activated. I'd like to avoid renaming all of my fields if possible, but I'm stuck on trying to find another solution. I've pasted the code for one of the forms below. The other 5 are almost identical, they are just for different types of applications...
Any help would be appreciated!
<?php$Name = $_POST['Name'];
$Email = $_POST['Email'];
$PhoneNumber = $_POST['PhoneNumber'];
$InstitutionalAssociation = $_POST['InstitutionalAssociation'];
$ProjectDescription = $_POST['ProjectDescription'];
$RADuties = $_POST['RADuties'];
$FundingSource1 = $_POST['FundingSource1'];
$FundingSource2 = $_POST['FundingSource3'];
$FundingSource3 = $_POST['FundingSource3'];
$FundingAmount1 = $_POST['FundingAmount1'];
$FundingAmount2 = $_POST['FundingAmount2'];
$FundingAmount3 = $_POST['FundingAmount3'];
$comments = $_POST['comments'];//begin form security check
function is_valid_email($Email) {
return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{¦}~]+@([0-9.]+¦([^\s]+\.+[a-z]{2,6}))$#si', $Email);
}function contains_bad_str($str_to_test) {
$bad_strings = array(
"content-type:"
,"mime-version:"
,"multipart/mixed"
,"Content-Transfer-Encoding:"
,"bcc:"
,"cc:"
,"to:"
);
foreach($bad_strings as $bad_string) {
if(eregi($bad_string, strtolower($str_to_test))) {
echo "$bad_string found. Suspected injection attempt - mail not being sent.";
exit;
}
}
}function contains_newlines($str_to_test) {
if(preg_match("/(%0A¦%0D¦\\n+¦\\r+)/i", $str_to_test) != 0) {
echo "newline found in $str_to_test. Suspected injection attempt - mail not being sent.";
exit;
}
}if($_SERVER['REQUEST_METHOD'] != "POST"){
echo("Unauthorized attempt to access page.");
exit;
}if (!is_valid_email($Email)) {
echo 'Sorry, invalid email';
exit;
}contains_bad_str($Email);
contains_bad_str(body);contains_newlines($Email);
//end form security check$title = "Thank-you";
$Name = HTMLSpecialChars($Name);
$Email = HTMLSpecialChars($Email);
$ProjectDescription = HTMLSpecialChars($ProjectDescription);
$RADuties = HTMLSpecialChars($RADuties);
$FundingSource1 = HTMLSpecialChars($FundingSource1);
$FundingSource2 = HTMLSpecialChars($FundingSource2);
$FundingSource3 = HTMLSpecialChars($FundingSource3);
$comments = HTMLSpecialChars($comments);// Email Message
echo "<p>";
$mail_to = "email@email.com";
$mail_subject = "Funding Application Form";
$mail_body = "Application Form\n\n Name: $Name\n Email: $Email\n Phone Number: $PhoneNumber\n Institutional Association: $InstitutionalAssociation\n Project Description: $ProjectDescription\n RA Duties: $RADuties\n $Funding Source 1: $FundingSource1 $FundingAmount1\n $Funding Source 2: $FundingSource2 $FundingAmount2\n $Funding Source 3: $FundingSource3 $FundingAmount3\n Comments: $comments";