简体   繁体   中英

Simple Contact Form Doesn't Work without IE Developer Toolbar Open

I have a simple contact form that works in every browser, except IE. It will work with IE only if I have IE's developer toolbar (DT) open. Since I cannot ask people to press F12 if they're using IE, could someone explain to me why IE is such a pain...doesn't like the code? And I can't use the developer tool since the code works when it runs.

What it does when successful: You stay on the same page and a message pops up thanking you for your submission. Data is stored in a database and an email is sent.

What IE without DT open: You redirect to the .php address and have nothing, but the result text. The data is not stored in the database and an email is sent with all info, except the 'Comment' piece.

Of course it starts out in HTML with a little JavaScript in the beginning...

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
     <title></title>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
    <link rel="stylesheet" href="css/default.css" />
    <script type="text/javascript">
      $(function() {
        $('#submit').click(function() {
        $('#mbcontainerloading').append('<img src="img/loading.gif" alt="Currently Loading" id="loading" />');

            var name = $('#name').val();
            var email = $('#email').val();
            var comments = $('#comments').val();
            var mathq = $('#mathq').val();

            console.log(name,email,comments,mathq); 

            $.ajax({
                url: 'submit_to_db.php',
                type: 'POST',
                data: 'name=' + name + '&email=' + email + '&comments=' + comments + '&mathq=' + mathq, 


                success: function(result) {
                    $('#response').remove();
                    $('#mbcontainerresponse').append('<p id="response">' + result + '</p>');
                    $('#loading').fadeOut(500, function() {
                        $(this).remove();
                    });
                console.log(result);
                }
            });

            return false;
        });

      });
    </script>
     </head>
      <body>
<form action="submit_to_db.php" method="post">

       <div id="mbcontainer">
        <label for="name">Name</label>
    <input type="text" name="name" id="name" />

    <label for="email">Email Address</label>
    <input type="text" name="email" id="email" />

    <label for="comments">Comments/Concerns</label>
    <textarea rows="5" cols="35" name="comments" id="comments"></textarea>

    <label for="mathq">What is 9 + 3?<br />
    <span class="mathc">(Please answer the question to prevent spam)</span></label>
    <input type="text" name="mathq" id="mathq" />

    <br />
    <input type="submit" name="submit" id="submit" value="Go!" />

    </div>
<div id="mbcontainerloading">
</div>
<div id="mbcontainerresponse">
</div>
</form>
      </body>
    </html>

When I submit in IE without Developer Toolbar (DT), I'm moved to the actual .php page. This should work and does on other browser as leaving you on the page and update from the php portion of the code, which is...

    <?php


    include("dogspw/dogs.inc");
    $cxn = mysqli_connect($host,$user,$passwrd,$hotel) or die ("couldn't connect to server");
    $query = "INSERT into commentsa(name, email, comments, mathq) VALUES (?, ?, ?, ?)";
if ($_POST['mathq']==12) { 
    $stmt = $cxn->stmt_init();
    echo $_POST['name']."<br />";
    echo $_POST['email']."<br />";
    echo $_POST['comments']."<br />";
    echo $_POST['mathq']."<br />";
    if($stmt->prepare($query)) {
        $stmt->bind_param('ssss', $_POST['name'], $_POST['email'], $_POST['comments'], $_POST['mathq']);
        $stmt->execute();
    }

        if($stmt) {
        echo "Thank you. We'll be in touch with you shortly!";
        } else {
        echo "There was a problem. Please try again later.";
        }
echo "...And thanks for answering the question correctly!";
}   
else {
echo "Did you answer the math question?  Your comment was not sent.";
}   
    //setup email

    $to='john@smith.com';
    $subject='Question from smith.com';
    $number=$_POST['mathq'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $questiona=$_POST['comments'];
    $message="Name:  ".$name. "\r\n" . "Email:  " .$email. "\r\n" . "Question:  " .$questiona;


    if ($number==12){
    mail($to,$subject,$message);
    echo '<br /><span style="background-color:#dfe0fc">An email has been sent to me, as well.<br />Just in case...<a href="http://www.smith.com"><span style="text-decoration: none">Go back to Smith</span></span></a>';
    }
    else 
    {
    echo '<br /><span style="background-color:#dfe0fc">An email was not sent, either.<br />
    Just in case...<a href="http://www.smith.com"><span style="text-decoration: none">Go back to smith</span></span></a>';
    }

    ?>

I've walked through each step and obviously do not know that one tweak IE requires for this to run. I've verified that the info is getting to the .php file, and get the response of "Thank you. We'll be in touch with you shortly!" Not sure where to go from here. Please help, I greatly appreciate your time and thank you in advance.

remove the console.log calls. console is undefined in IE, if the developers toolbar is closed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM