• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Redirect after form submission i not working in IE 11

Engaged ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

I created a from, which after successful submission shows a "Thankyou" pages.

Success is when the form fields are verified and if there is a file it was uploaded to the server.

In all browsers, both the message and attached files are send properly - I received the email to my inbox, however, in FireFox and Chrome I am redirected to the "ThankYou" page after the successful submission.

In IE 11 it is not redirecting at all.

The link to this page is:

http://dnd-production.com/_english/contactOrder.php?page=Contact_Us

I use ob_start(); & ob_flush(); just for safety on the "Thankyou" page.

The form is defined:

  <form id="formmail" class="form-horizontal col-12 col-sm-8 col-md-7 offset-md-1" name="formmail" method="POST" action="<?php echo siteRoot()?>/_scripts/uploadAndSend.php" enctype="multipart/form-data">

This is the submit function:

    $('form[name="formmail"]').submit(function (event) {
      "use strict";
      event.preventDefault(); //prevent default action
      if (!checkForm()) {
        return false;
      } else {
        console.log("passed check");
        var post_url = $(this).attr("action"); //get form action url
        var request_method = $(this).attr("method"); //get form GET/POST method
        //form_data.append('language', $('input[name=language]')[0]);
  
        // Attach file
        var form_data = new FormData();
        var myform = $('form[name="formmail"]'); // specify the form element
        //var myform = $("#formmail"); // specify the form element
        var idata = myform.serializeArray();
        var file_data = $("#browseButton").prop("files")[0];
  
        form_data.append("fileatt", file_data);
  
        $.each(idata, function (key, input) {
          form_data.append(input.name, input.value);
        });
        //alert(form_data);
        $.ajax({
          url: post_url,
          //type: "POST",
          //dataType:'json',
          type: request_method,
          data: form_data,
          contentType: false,
          processData: false,
          xhr: function () {
            //upload Progress
  
            var xhr = $.ajaxSettings.xhr();
            if (xhr.upload) {
              xhr.upload.addEventListener("progress", function (event) {
  
                var percent = 0;
                var position = event.loaded || event.position;
                var total = event.total;
                if (event.lengthComputable) {
                  percent = Math.ceil(position / total * 100);
                }
                //update progressbar
                $(".progress-bar").css("width", percent + "%");
                $(".progress-bar").html(percent + "%");
                //$("#upload-progress .progress-bar").css("width", + percent +"%");
              }, true);
            }
            return xhr;
          }
        }).done(function (response) { //
          $("#server-results").html(response);
        });
      }
    });

/////////

Redirection to the Thankyou page occurs here:

    <?php ob_start(); ?>
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
    <?php
    $host = $_SERVER['HTTP_HOST'];
    if(strpos($host, "dnd-production.com") !== false){
    $site_Root = "http://$host";
    } else {
        $uri   = explode("/", $_SERVER['PHP_SELF']);
    //print_r($uri);
    $site_Root = "//$host/$uri[1]/";
    }
 
    if(isset($_GET['lang'])) {
      $lang = $_GET['lang'];
    } else {
      $lang = "he";
    }
    if($lang == "en") {
    $thankYouPage = "${site_Root}/_english/thankyou.php?page=null";
    } else {
    $thankYouPage = "${site_Root}/_pages/thankyou.php";
    }
    echo "<meta http-equiv=\"refresh\" content=\"0; url=$thankYouPage\">";
    ?>
  
    <title>Email Form</title>
    </head>
  
    <body onLoad="Refresher(1)">
    <?php
  
    $to = 'info@dnd-production.com';
  
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $comments = $_POST['message'];
    $phone = $_POST['phone'];
    $from = $email;
    $lang     = $_POST['language'];
 
    // Get html message content
    $form_data  = "<p>This email is from <span class=\"bold\">$name</span></p> \n\n ";
    $form_data .= "<p>Phone: $phone</p>";
    $form_data .= "<p>Email: $email</p>";
    $form_data .= "<h3>$subject</h3>";
    $form_data .= "<p>$comments</p>";
    $message =    "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \n" .
                      "    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> \n" .
                      "<html xmlns=\"http://www.w3.org/1999/xhtml\"> \n" .
                      "<head> \n" .
                      "  <meta http-equiv=\"content-type\" content= \n" .
                      "  \"text/html; charset=UTF-8\" /> \n" .
                      "<style type=\"text/css\"> \n" .
                      "body {    font-size: 9pt; font-family:  verdana, sans-serif;     color: #000; background:#fff; }  \n" .
                      ".bold { font-weight: bold; }  \n" .
                      "</style>  \n" .
                      "</head> \n" .
                      "<body>$form_data \n" .
                      "</body> \n" .
                      "</html> \n\n";
  
    $headers = "From: $from";
    // Obtain file upload vars
    if(isset($_FILES['fileatt'])){
      $fileatt      = $_FILES['fileatt']['tmp_name'];
      $fileatt_type = $_FILES['fileatt']['type'];
      $fileatt_name = $_FILES['fileatt']['name'];
      $fileatt_size = $_FILES['fileatt']['size']/1024;//size in KBs
  
      if (is_uploaded_file($fileatt)) {
        // Read the file to be attached ('rb' = read binary)
        $file = fopen($fileatt,'rb');
        $data = fread($file,filesize($fileatt));
        fclose($file);
        // Generate a boundary string
        $semi_rand = md5(time());
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
        // Add the headers for a file attachment
        $headers .= "\nMIME-Version: 1.0\n" .
                 "Content-Type: multipart/mixed;\n" .
                 " boundary=\"{$mime_boundary}\"";
        // Add a multipart boundary above the html message
        $message = "This is a multi-part message in MIME format.\n\n" .
               "--{$mime_boundary}\n" .
               "Content-Type: text/html; charset=\"UTF-8\"\n" .
               "Content-Transfer-Encoding: 7bit\n\n" .
               $message . "\n\n";
                    
        // Base64 encode the file data
        $data = chunk_split(base64_encode($data));
        //We now have everything we need to write the portion of the message that contains the file attachment. Here's the code:
        //Add file attachment to the message
        $message .= "--{$mime_boundary}\n" .
                  "Content-Type: {$fileatt_type};\n" .
                  " name=\"{$fileatt_name}\"\n" .
                  "Content-Disposition: attachment;\n" .
                  " filename=\"{$fileatt_name}\"\n" .
                  "Content-Transfer-Encoding: base64\n\n" .
                  $data . "\n\n" .
                  "--{$mime_boundary}--\n";
      }
    }
    //end if is_uploaded_file
    else {
      // Generate a boundary string
      $semi_rand = md5(time());
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
      // Add the headers for a file attachment
      $headers .= "\nMIME-Version: 1.0\n" .
                  "Content-Type: multipart/mixed;\n" .
                  " boundary=\"{$mime_boundary}\"";
      // Add a multipart boundary above the html message
      $message = "This is a multi-part message in MIME format.\n\n" .
                 "--{$mime_boundary}\n" .
                 "Content-Type: text/html; charset=\"UTF-8\"\n" .
                 "Content-Transfer-Encoding: 7bit\n\n" .
                 $message . "\n\n";
    }                      
    mail($to, $subject, $message, $headers);
    ?>
    </body>
    </html>
    <? ob_flush(); ?>

Views

426

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation