Jump to content

Footer chopped off error message


virtual

Recommended Posts

Hi Guys,

Me again with another JS question. I changed the form I was using and now have a new one, but I cannot get it to show the rest of the page and the footer which is an include in the error message. Can anyone tell me where I went wrong? Thanks

 

Here is the script

$email_to = "o****ds@comcast.net";
   $email_subject = "Request from ****.com";
   $close_divs = '</div></div>
                     <div id="content-bottom"></div>
<?php include ('includes/footer.php'); ?>
   </div><!-- END CONTENT -->
</div>
<!-- END CONTAINER -->
</body>
</html> ';   



   function died($error) {
       //  error code here
       echo "We are very sorry, but there were error(s) found with the form you submitted. ";
       echo "These errors appear below.<br /><br />";
       echo $error."<br /><br />";
       echo "Please go back and fix these errors.<br /><br />";
echo $close_divs;	
       die();
   }

   // validation expected data exists
   if(!isset($_POST['name']) ||
       !isset($_POST['email']) ||
       !isset($_POST['telephone']) ||
       !isset($_POST['comments'])) {
       died('We are sorry, but there appears to be a problem with the form you submitted.');      
   }


   $name = $_POST['name']; // required
   $email_from = $_POST['email']; // required
   $telephone = $_POST['telephone']; // not required
   $comments = $_POST['comments']; // required

   $error_message = "";
   $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 if(!preg_match($email_exp,$email_from)) {
   $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 }
   $string_exp = "/^[A-Za-z .'-]+$/";
 if(!preg_match($string_exp,$name)) {
   $error_message .= 'The Name you entered does not appear to be valid.<br />';
 }
 if(strlen($comments) < 2) {
   $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 }
 if(strlen($error_message) > 0) {
   died($error_message);
 }

   $email_message = "Form details sent from g****o.com: \n\n";

   function clean_string($string) {
     $bad = array("content-type","bcc:","to:","cc:","href");
     return str_replace($bad,"",$string);
   }


   $email_message .= "Name: ".clean_string($name)."\n";
   $email_message .= "Email: ".clean_string($email_from)."\n";
   $email_message .= "Telephone: ".clean_string($telephone)."\n";
   $email_message .= "Comments: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>

<!-- success html here -->

Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>

Edited by virtual
Link to comment
Share on other sites

I don't believe you can do an include within a PHP variable, like you are trying to do with $close_divs. At the very least, I played with it a little while and couldn't get it to work. Either you have to go about this in a completely different way, or perhaps try the file_get_contents() function (http://php.net/manual/en/function.file-get-contents.php).

Link to comment
Share on other sites

Thanks Ben, I tried taking out the php include and it still doesn't close the divs. I can live without the footer content in the error message, I would just like it to close out the design which has a rounded background image.

 

I tried your link but got a 404 message :(

Link to comment
Share on other sites

So when you test this, what is the last thing that you see on the page? The "Please go back and fix these errors." message? If you view the source code of the form in the browser after you submit it, do you see any error messages in the source?

 

Sorry, the link is http://php.net/manual/en/function.file-get-contents.php . Apparently the forum included the ")." in the link incorrectly.

Link to comment
Share on other sites

This is the error message from the source code,

We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.<br /><br />The Email Address you entered does not appear to be valid.<br /><br /><br />Please go back and fix these errors.<br /><br />

 

As you can see it does not close the divs, body and html tag.

Link to comment
Share on other sites

After looking at the code again, this is what I realized: your $close_divs variable is defined outside of the died() function, which means that the function can't access it. You should be able to fix it by adding one line:

function died($error) {
       global $close_divs;

       //  error code here
       echo "We are very sorry, but there were error(s) found with the form you submitted. ";
       echo "These errors appear below.<br /><br />";
       echo $error."<br /><br />";
       echo "Please go back and fix these errors.<br /><br />";
       echo $close_divs;       
       die();
   }

And obviously make sure you don't try to use an include when you define the $close_divs variable.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...