Why does footer disappear when form is submitted?

时间:2016-07-07 02:09:31

标签: javascript php forms

This function will display a message if an element within the form is missing or will display Message send.

<link rel="stylesheet" href="fournav.css">

  <script type="text/javascript">

  function CustomAlert(){   

      this.render = function(missdata)

       {

          var winW = window.innerWidth;

          var winH = window.innerHeight;

          var dialogoverlay = document.getElementById('dialogoverlay');

          var dialogbox = document.getElementById('dialogbox');

          dialogoverlay.style.display = "block";

          dialogoverlay.style.height = winH+"px";

          dialogbox.style.left = (winW/2) - (300 * .5)+"px"; 

          dialogbox.style.top = "100px";

          dialogbox.style.display = "block";

          document.getElementById('dialogboxhead').innerHTML = 
             "You forgot to enter";

          document.getElementById('dialogboxbody').innerHTML = missdata;

          document.getElementById('dialogboxfoot').innerHTML = 
              '<button onclick="Alert.ok()">OK</button>';

      }
      this.ok = function()

         {

          document.getElementById('dialogbox').style.display = "none";

          document.getElementById('dialogoverlay').style.display = "none";

        }

      }

  var Alert = new CustomAlert()

  function clearform()
      {

      document.getElementById("name").value=""; 

      document.getElementById("email").value="";

      document.getElementById("message").value="";

      }

  </script>

</head>

# When the Alert.render is executed the footer disappear. Any block element that is place below will disappear.#

            <div id="dialogboxhead"></div>

            <div id="dialogboxbody"></div>

             <div id="dialogboxfoot"></div>

  </div>

  </div>


  <div class="main_body">

          <div class="main_body2">

            <form  id=myform name=contactf method="post">

                <ul>
                    <li class="clabel">

                    <label class="clabel" for="name">Full Name *</label>

                    <input class="iform" type="text" name="name" id="name"

                            placeholder="Please enter your full name" 

                            value="<?php echo isset($_POST['name'])?  
                            $_POST['name'] : '' ?>"/>

                    </li>

                    <li class="clabel">

                    <label class="clabel" for="email">Email *</label>

                    <input class="iform" name="email"  id="email"

                           type="email" placeholder="Enter you Email address" 

                                 value="<?php echo isset($_POST['email']) ? 

                                 $_POST['email'] : '' ?>" />

                    </li>

                    <li class="clabel">

                    <label class="clabel" for="message">Message *</label>

                    <textarea class="iform"   name="message"  id="message" 

                      placeholder="Please enter your comments or questions">

                      <?php echo isset($_POST['message']) ? $_POST['message'] 
                            : '' ?></textarea>

                    </li>

                    <li>

                    <input class="submitb" name="submit" id="submit" 

                           type="submit" value="SEND">  

                    </li>

                  </ul>

                        <?php 

                        $var45='edgad';

                        $var36='att';

                        $no23='.';

                        $no21='na1';

                        $f92='@';

                        $r67='net';

                        $qyt=$var45.$no21.$f92.$var36.$no23.$r67;

                        if (isset($_POST['submit']))

                        {

                        $name = 

                        trim(stripslashes(htmlspecialchars($_POST['name'])));

                       $email = 

                       trim(stripslashes(htmlspecialchars($_POST['email'])));

                       $message = 

                     trim(stripslashes(htmlspecialchars($_POST['message'])));  

                        $mailTo = $qyt;

                        $msgSubject = "Requesting Information ";

                        $msgBody = "From:  $name,\n\r Email:  $email,\n\r 

                                    Message:\n\r$message";


                        $xHeaders = "From: $email" . phpversion();

                            if ($_POST['name'] == "" )
                            {

                              echo '<script

                               type="text/javascript">

                               ','Alert.render("Your Full Name, click ok to 

                                 continue")','</script>';

                              exit;
                            }

                            else if ($_POST['email'] == "")
                            {

                              echo '<script 

                              type="text/javascript">','Alert.render("Your 

                              Email Address, click ok to continue")','

                              </script>';

                              exit;
                            }

                            else if ($_POST['message'] == "")
                            {

                              echo '<script 

                              type="text/javascript">','Alert.render("Your                 

                              Messages, click ok to continue")','</script>';

                              exit;
                            }

                            else
                            {
                            ?>
                      <div class="thhh">

                      Thanks for Your Email!<br>Your message has been sent.  

                      <br><br><a href="index.html">Click here to continue</a>

                      </div>


                           <?php

                          mail($mailTo, $msgSubject, $msgBody, $xHeaders);

                          $mailTo = $email;

                          $msgSubject = "Thank You for your email.";

                          $msgBody = "Thank you for your email. We will

                            respond to you as soon as possible.\n\r";

                          $xHeaders = "From: $qyt". phpversion();

                          mail($mailTo, $msgSubject, $msgBody, $xHeaders);

                          echo '<script type="text/javascript">', 

                          'clearform();', '</script>';

                          exit;

                          }

                       }

                          ?>
            </form>

      </div>

  </div> 

  <footer class="cindex">

      <ul class="footul">

          <li class="fli"><a class="btab" href="index.html">&nbsp;HOME&nbsp;</a></li>

          <li class="fli"><a class="btab" href="nav2.html"> SERVICE</a></li>

          <li class="fli"><a class="btab" href="nav3.html">Whats for Sale</a></li>

          <li class="fli"><a class="btab" href="contact.php">CONTACT</a></li>

       </ul>

      <p class="kshowc">&nbsp;&#0169;<span class="yourc">Your Company</span> 

                    2016. All rights reserved.&nbsp;</p>

      <p class="smft"> Website by <span class="yourc 

                   wrjm">Cfhshshgdsghf</span></p>

  </footer>

1 个答案:

答案 0 :(得分:0)

在显示之前退出php脚本:

Messages, click ok to continue")','</script>';

                          exit;

只需删除所有退出语句,如下所示:

  <div id="dialogboxhead"></div>

        <div id="dialogboxbody"></div>

         <div id="dialogboxfoot"></div>

      <div class="main_body2">

        <form  id=myform name=contactf method="post">

            <ul>
                <li class="clabel">

                <label class="clabel" for="name">Full Name *</label>

                <input class="iform" type="text" name="name" id="name"

                        placeholder="Please enter your full name" 

                        value="<?php echo isset($_POST['name'])?  
                        $_POST['name'] : '' ?>"/>

                </li>

                <li class="clabel">

                <label class="clabel" for="email">Email *</label>

                <input class="iform" name="email"  id="email"

                       type="email" placeholder="Enter you Email address" 

                             value="<?php echo isset($_POST['email']) ? 

                             $_POST['email'] : '' ?>" />

                </li>

                <li class="clabel">

                <label class="clabel" for="message">Message *</label>

                <textarea class="iform"   name="message"  id="message" 

                  placeholder="Please enter your comments or questions">

                  <?php echo isset($_POST['message']) ? $_POST['message'] 
                        : '' ?></textarea>

                </li>

                <li>

                <input class="submitb" name="submit" id="submit" 

                       type="submit" value="SEND">  

                </li>

              </ul>

                    <?php 

                    $var45='edgad';

                    $var36='att';

                    $no23='.';

                    $no21='na1';

                    $f92='@';

                    $r67='net';

                    $qyt=$var45.$no21.$f92.$var36.$no23.$r67;

                    if (isset($_POST['submit']))

                    {

                    $name = 

                    trim(stripslashes(htmlspecialchars($_POST['name'])));

                   $email = 

                   trim(stripslashes(htmlspecialchars($_POST['email'])));

                   $message = 

                 trim(stripslashes(htmlspecialchars($_POST['message'])));  

                    $mailTo = $qyt;

                    $msgSubject = "Requesting Information ";

                    $msgBody = "From:  $name,\n\r Email:  $email,\n\r 

                                Message:\n\r$message";


                    $xHeaders = "From: $email" . phpversion();

                        if ($_POST['name'] == "" )
                        {

                          echo '<script

                           type="text/javascript">

                           ','Alert.render("Your Full Name, click ok to 

                             continue")','</script>';


                        }

                        else if ($_POST['email'] == "")
                        {

                          echo '<script 

                          type="text/javascript">','Alert.render("Your 

                          Email Address, click ok to continue")','

                          </script>';

                        }

                        else if ($_POST['message'] == "")
                        {

                          echo '<script 

                          type="text/javascript">','Alert.render("Your                 

                          Messages, click ok to continue")','</script>';

                        }

                        else
                        {
                        ?>
                  <div class="thhh">

                  Thanks for Your Email!<br>Your message has been sent.  

                  <br><br><a href="index.html">Click here to continue</a>

                  </div>


                       <?php

                      mail($mailTo, $msgSubject, $msgBody, $xHeaders);

                      $mailTo = $email;

                      $msgSubject = "Thank You for your email.";

                      $msgBody = "Thank you for your email. We will

                        respond to you as soon as possible.\n\r";

                      $xHeaders = "From: $qyt". phpversion();

                      mail($mailTo, $msgSubject, $msgBody, $xHeaders);

                      echo '<script type="text/javascript">', 

                      'clearform();', '</script>';

                      exit;

                      }

                   }

                      ?>
        </form>

  </div>

  <ul class="footul">

      <li class="fli"><a class="btab" href="index.html">&nbsp;HOME&nbsp;</a></li>

      <li class="fli"><a class="btab" href="nav2.html"> SERVICE</a></li>

      <li class="fli"><a class="btab" href="nav3.html">Whats for Sale</a></li>

      <li class="fli"><a class="btab" href="contact.php">CONTACT</a></li>

   </ul>

  <p class="kshowc">&nbsp;&#0169;<span class="yourc">Your Company</span> 

                2016. All rights reserved.&nbsp;</p>

  <p class="smft"> Website by <span class="yourc 

               wrjm">Cfhshshgdsghf</span></p>