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
how do i display data on a page from mysql
1 - do i use this code at the top of each of my page i wish to only alow access if there as been a s
How to ... (FAQs)
... get e-mail notifications
As several people asked how to get e-mail notifications when new posti
Reading Most Recent CSV File in Directory
I thought I had wrapped this project up, but found out that the program I use to FTP a csv file to m
how do i display data on a page from mysql
1 - do i use this code at the top of each of my page i wish to only alow access if there as been a s
Is there something wrong?
Hi all,
Just a quick question... can someone look at this code and see if something is wrong?
How to implement HTTP connection timeout
Hi All,I would like to implement an HTTP connection timeout.
I am working on a application wh
echo $rows help
Hi all,
Hopefully something simple that I don't know!
I have this:
Code: [Selec
parse error
Parse error: syntax error, unexpected '[', expecting ')' in /Users/admin/Sites/phptest/array.php on
Contents of variable not echoing
Hey guys, hopefully this is an easy one...
In this line, the variables are not echoing out. T
getting weird error..
okay, I'm getting an error on this particular function, something about the syntax in the mysql LIMI