0

I am trying to set up a contact form in Bootstrap with a PHP file that sends information and routes to a Bootstrap modal.

The form was successfully sent to Chrome, Safari and Firefox. The problem with Firefox is that after submit it goes to the Bootstrap modal but quickly bounces to a Firefox error message.

I would appreciate any help in correcting this error. Error message said: “Corrupted Content Error” The page you are trying to view cannot be shown because an error in data transmission was detected.

I have included sections of html coding/Bootstrap and PHP file. I am using Firefox 35.0.2, Chrome 43.0.2357.124, Safari 7.1.6

Thank you. Cindy Jones-Hulfachor

////////

<?php
 
if(isset($_POST['email'])) {
    $email_to = "cdhulf@bellsouth.net";
    $email_subject = "Portfolio site email";
 
    function died($error) {
        echo "We are very sorry, but there were error(s) found with the information you provided. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
 
// validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the information you provided.');       
    }
 
    $first_name = $_POST['first_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,$first_name)) {
    $error_message .= 'The name you entered does not appear to be valid.<br />';
  }
 
  if(strlen($comments) < 2) {
    $error_message .= 'The information that you entered do not appear to be valid.<br />';
  }
 
  if(strlen($error_message) > 0) {
    died($error_message);
  }
 
    $email_message = "Form details below.\n\n";
 
function clean_string($string) {
  $bad = array("\\","content-type","href");
  return str_replace($bad,"",$string);
  }
 
    $email_message .= "First Name: ".clean_string($first_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);  

header("location:javascript://history.go(-1)");
}
?>
<?php
<div class="col-sm-6">
    <div class="footer-content">
    
    <form name="contactform" method="post" action="send_email_form.php" role="form" id="footer-form">
            <div class="form-group has-feedback">
                <label class="sr-only" for="first_name">Name</label>
                <input type="text" class="form-control" id="first_name" placeholder="Name" maxlength="50" size="30" name="first_name" required>
                <i class="fa fa-user fa-margin-top form-control-feedback"></i>
            </div>
            <div class="form-group has-feedback">
                <label class="sr-only" for="email_from">Email address</label>
                <input type="text" class="form-control" id="email" placeholder="Email" maxlength="80" size="30" name="email" required>
                <i class="fa fa-envelope fa-margin-top form-control-feedback"></i>
            </div>
            <div class="form-group has-feedback">
                <label class="sr-only" for="telephone">Phone</label>
                <input type="text" class="form-control" id="telephone" placeholder="Phone (Optional)" maxlength="30" size="30" name="telephone">
                <i class="fa fa-phone fa-margin-top form-control-feedback"></i>
            </div>
            <div class="form-group has-feedback">
                <label class="sr-only" for="comments">Message</label>
                <textarea class="form-control" rows="5" id="comments" placeholder="Thoughts" name="comments" required></textarea>
                <i class="fa fa-pencil fa-margin-top form-control-feedback"></i>
            </div>
            <input type="submit" value="Send" class="btn btn-default" href="#project-form" data-toggle="modal" data-target="#project-form">
        </form>
    </div>
</div>
Siguza
  • 21,155
  • 6
  • 52
  • 89
  • Delete the last – Alex Coloma Jun 12 '15 at 06:36
  • Makinovic, Took out <$php at end, took out @ in mail, added $headers in same line and took out coding for redirect to previous page header("location:javascript://history.go(-1)"); It was the header(‘location: coding causing the Firefox error message. So now I got PHP to route back to page with this code ... (THIS ROUTES TO SITE) echo ' '; The last code I needed was to route to modal #project-form at website. I can't seem to find anything to work. Thanks for your help. – CindyJonesHulfachor Jun 13 '15 at 18:40
  • You can add one parameter to your link like this: portfolio.cindyjoneshulfachor-visuals.com?success=true, and then work with that parameter (http://stackoverflow.com/questions/19491336/get-url-parameter-jquery) showing your modal or not from jquery. – Alex Coloma Jun 15 '15 at 06:20
  • To route back to Site from PHP I used this. mail($email_to, $email_subject, $email_message, $headers); echo ' '; I ran out of time on trying to route from PHP to bootstrap modal. Thanks for your help. – CindyJonesHulfachor Jun 27 '15 at 06:31

0 Answers0