Form always sends to error page...
Posted on
16th Feb 2014 07:03 pm 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 ;
?>
Your Answer:
Login to answer
62
25
Other forums
Why use OOP?
Can someone explain to me why I should use OOP instead of procedure based code.
Im building a
need help with php get
i have a option box that gets filled with dates, but how do i get once the option value has been cli
Displaying different page content, depending on the logged in user.
Hi all, I am new to ASP.net (and web development in general), and have a question about how I can di
Need help with an email blocker for a guessbook
I am new with php and here is a simple guessbook page but I am being hit with spam from a group of t
for some reason mysql query not working, not inserting, please check it out
This code is not inserting anything into my db, don't know why, the $_SESSION variable does contain
Firewall / visited websites logger
Hi.
I have a firewall implementation and I want to log all the websites visited on the machine. S
whats wrong with my code please help!!!
this is the error
Warning: mysql_close(): supplied argument is not a valid MySQL-Link res
Production Order Enterprise Service to Manufacturing Exctn Sys (MES) ???
Hello Experts,
In our current landscape SAP ECC 5.0 is integrated to MES system via PI 7.
Edit MySQL Row Using PHP and HTML Form
Hello,
Here's what I'm trying to do. Build a page where a user enters a MySQL row number in.
Quick fix: Conditional statement with an array
Hi, I'm getting the temperature value off of the Environment Canada website along with the icon file