ismaZulfiqar Posted February 9, 2011 Share Posted February 9, 2011 I am trying to put a check on fields in the form in following code but it always gives Incomplete Submission error. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>BEAU Enquiry</title> <link href="css/beau-style.css" rel="stylesheet" type="text/css" /> </head> <body> <h2>Enquiry Submission Status</h2> <?php /*************************** * Configuration * ***************************/ // Who should this message be sent to? $to = "[email protected]"; // Contact subject $subject = "BEAU Enquiry Submission"; // Details $message=Trim(stripslashes($_POST['$detail'])); // Mail of sender $mail_from= Trim(stripslashes($_POST['$EmailAddress'])); // From $name = $FirstName." ".$LastName; $header="From: $name <$mail_from>"; /*************************** * End of Configuration * ***************************/ // Validation // Check we have recieved post data - don't just send out an empty e-mail $validationOK=true; if (empty($mail_from) || empty($message) || empty($_POST['$FirstName']) || $_POST['$LastName']) $validationOK=false; if (!$validationOK) { print "Incomplete submission! You should use your browsers back button, return to the previous page and fill ALL the fields."; } // The form passed validation and the message will be sent. else { // Build up the message to be sent $message = "Users IP Address: ".$_SERVER["REMOTE_ADDR"]."\n"; // IP address $message .= "Submission Date: ".date("d-M-Y")."\n"; // Date of message sending $message .= "Form Location: ".$_SERVER["HTTP_REFERER"]."\n\n"; // Form the request came from // Iterate through the data we have recieved and build up the message while(list($name, $value) = each($_POST)) { // ensure multiple items from a select box are included correctly. if (is_array($value)) { foreach($value as $subvalue) { $newValue .= $subvalue."\n"; } $value = $newValue; } // Create an array of strange looking code. If we spot any of these // anywhere the sender may be up to no good! $suspiciousCode = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i"); // If we see and suspicious code, replace it with the words '***removed***' $value = preg_replace($suspiciousCode, "***removed***", $value); // Append the text to the message $message .= ucfirst($name).": \t".stripslashes(strip_tags(wordwrap($value,65)))."\n"; } $send=mail($to,$subject,$message,$header); // Check, if message sent to your email // display message "We've recived your information" if($send){ echo "We've received your enquiry and will get back to you soon!";} else { echo "ERROR Sending Form";} } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/227156-form-validation-isnt-working/ Share on other sites More sharing options...
zenlord Posted February 9, 2011 Share Posted February 9, 2011 Change if (!$validationOK) to if ($validationOK==false) V Link to comment https://forums.phpfreaks.com/topic/227156-form-validation-isnt-working/#findComment-1171769 Share on other sites More sharing options...
ismaZulfiqar Posted February 9, 2011 Author Share Posted February 9, 2011 still does not work Although if i remove the validation check, email is sent with the data in it(header does not work though :S ) Link to comment https://forums.phpfreaks.com/topic/227156-form-validation-isnt-working/#findComment-1171816 Share on other sites More sharing options...
Jessica Posted February 9, 2011 Share Posted February 9, 2011 Where are FirstName and LastName set? $name = $FirstName." ".$LastName; $header="From: $name <$mail_from>"; Link to comment https://forums.phpfreaks.com/topic/227156-form-validation-isnt-working/#findComment-1171819 Share on other sites More sharing options...
ismaZulfiqar Posted February 9, 2011 Author Share Posted February 9, 2011 Added the declaration and modified the code, still the same error. // From $FirstName = $_POST['$FirstName']; $LastName = $_POST['$LastName']; $name = $FirstName." ".$LastName; $header="From: $name <$mail_from>"; /*************************** * End of Configuration * ***************************/ // Validation // Check we have recieved post data - don't just send out an empty e-mail $validationOK=true; if (empty($mail_from) || empty($message) || empty($_POST['$FirstName']) || empty($_POST['$LastName'])) $validationOK=false; if ($validationOK==false) { print "Incomplete submission! You should use your browsers back button, return to the previous page and fill ALL the fields."; } Where are FirstName and LastName set? $name = $FirstName." ".$LastName; $header="From: $name <$mail_from>"; Link to comment https://forums.phpfreaks.com/topic/227156-form-validation-isnt-working/#findComment-1171826 Share on other sites More sharing options...
Jessica Posted February 9, 2011 Share Posted February 9, 2011 $FirstName = $_POST['$FirstName']; Is wrong. $FirstName = $_POST['FirstName']; Would probably be closer to what you need. Link to comment https://forums.phpfreaks.com/topic/227156-form-validation-isnt-working/#findComment-1171829 Share on other sites More sharing options...
ismaZulfiqar Posted February 9, 2011 Author Share Posted February 9, 2011 Thank you very much! Appreciate the help. Problem solved! $FirstName = $_POST['$FirstName']; Is wrong. $FirstName = $_POST['FirstName']; Would probably be closer to what you need. Link to comment https://forums.phpfreaks.com/topic/227156-form-validation-isnt-working/#findComment-1171842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.