Form always sends to error page...

Posted on 16th Feb 2014 by admin

Hello,
Any help will be greatly appreciated. I am having trouble getting multiple fields to be required, and with the if multiple errors section. I think that's where the problem is. When I click "Submit", no matter if I fill out every field (try it yourself) it sends me to the error page. The original generated script worked fine with just three fields until I added more required fields. Any suggestions for security enhancements (other than CAPTCHA codes) is appreciated, too.

Thank you!

Here's the Site: http://www.charitableprofitarrangement.org/contact.html

========================================== contactOriginal.php ==========================================

Code: <?php

$mailto = 'test@charitableprofitarrangement.org' ;
$subject = "CPA Contact Form" ;
$formurl = "http://www.charitableprofitarrangement.org/contact.html" ;
$errorurl = "http://www.charitableprofitarrangement.org/error.html" ;
$thankyouurl = "http://www.charitableprofitarrangement.org/thankyou.html" ;
$email_is_required = 1;
$firstname_is_required = 1;
$lastname_is_required = 1;
$city_is_required = 1;
$state_is_required = 1;
$subject_is_required = 1;
$message_is_required = 1;
$uself = 0;
$use_envsender = 0;
$use_sendmailfrom = 0;
$use_webmaster_email_for_from = 0;
$use_utf8 = 1;

$headersep = (!isset( $uself ) || ($uself == 0)) ? "rn" : "n" ;
$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
if (!isset( $use_envsender )) { $use_envsender = 0 ; }
if (isset( $use_sendmailfrom ) && $use_sendmailfrom) {
ini_set( 'sendmail_from', $mailto );
}
$envsender = "-f$mailto" ;
$firstname = $_POST['firstname'] ;
$lastname = $_POST['lastname'] ;
$organization = $_POST['organization'] ;
$phone = $_POST['phone'] ;
$email = $_POST['email'] ;
$website = $_POST['website'] ;
$subject = $_POST['subject'] ;
$message = $_POST['message'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if ($email_is_required && empty($email) || $firstname_is_required && empty($firstname) || $lastname_is_required && empty($lastname) || $city_is_required && empty($city) || $state_is_required && empty($state) || $subject_is_required && empty($subject) || $message_is_required && empty($message)) {
header( "Location: $errorurl" );
exit ;
}
if (preg_match( "^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email ) || preg_match( "/[rn]/", $firstname ) || preg_match( "/[rn]/", $lastname ) || preg_match( "/[rn]/", $city ) || preg_match( "/[rn]/", $state ) || preg_match( "/[rn]/", $subject ) || preg_match( "/[rn]/", $message)) {
header( "Location: $errorurl" );
exit ;
}
if (empty($email)) {
$email = $mailto ;
}

$fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;

if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
unset($process[$key][$k]);
if (is_array($v)) {
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
} else {
$process[$key][stripslashes($k)] = stripslashes($v);
}
}
}
unset($process);
}

$messageproper =
"This message was sent from:n" .
"$http_referrern" .
"------------------------------------------------------------n" .
"First Name: $firstnamen" .
"Last Name: $lastnamen" .
"Organization: $organizationn" .
"City: $cityn" .
"State: $staten" .
"Phone: $phonen" .
"Email: $emailn" .
"Website: $websiten" .
"Subject: $subjectn" .
"------------------------- MESSAGE -------------------------nn" .
$message .
"nn------------------------------------------------------------n" ;

$headers =
"From: "$firstname" <$fromemail>" . $headersep . "Reply-To: "$firstname" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" . $headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;

if ($use_envsender) {
mail( $mailto, $subject, $messageproper, $headers, $envsender );
}
else {
mail( $mailto, $subject, $messageproper, $headers );
}
header( "Location: $thankyouurl" );
exit ;

?>

Other forums