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
preg-match with a string and numbers
Hi, I can't get the expression to work for my preg_match, what I'd like is for it to match the strin
Production of mango in processing industry
Hi,
We have one scenario ,company is in process industry,they are manufacturing MANGO pul
Function to extract email attachments using PHP IMAP
function extract_attachments($connection, $message_number) {
$attachments = array();
type check while uploading
Hi Everyone,
How can I check the exact type of a file while uploading on my site?
Here
Page Reload
I am having issues getting a page to reload after I submit data to a database. This form should inp
need help with mail()
hi i want to send an email with attaching pdf file using php. i have the following script but the pr
Problem with a select distinct
I have a problema with a select distinct, I have the next sql:
select distinct a,b,c,d fr
dynamic table with forms
I have a table that is populated with mysql data and in teh first column there is a raido button tha
PHP template help
Ok, I don't know if anyone can help me but I am using PHP templates to make a site. I am a newbie an
CHECH A STRING FOR ' " ' (DOUBLE QUOTES)
I am checking for delimiter (.!?) and if there is a " after a sentence then it should neglect a