dongyi0210 2016-08-23 11:19
浏览 42
已采纳

PHP电子邮件表单中的锚标记

Can you please help anybody?

I have made a mail form with PHP. This form is all the way at the bottom of the page. When I click send (this is an input tag), if there are errors, it will display them above the form.

But when you click on send the page will first go back to the top and you have to scroll all the way down to see if you have made any errors.

So is it possible to keep the page from jumping back the the start?

I know it was been solved many times e.g. here Is it possible not to jump to the top of the page on form submit? but enclose this code it will still scrool above contact section in the portfolio section...... my page svejdamartin.com Do you have any ideas ?

<footer>
  <section id="contact">                   
    <div class="row">
      <div class="col-md-6 col-md-offset-3">
        <div id="fourth">
          <h1>Contact Form</h1>
          <p>Please, do not hesitate to contact me if you want to get more information.</p>
           <?php
             if (isset($_GET['sent']) === true) { // ne POST ale GET //
               echo '<div class="alert alert-success" role="alert">Thank you, I will be in touch</div>'; // toto se vypise po odeslani vzkazu //

             } else {  //tento tag konci az na konci formulare !!! Otevrel jsem tam php a ukoncil tento else //
               if (empty ($errors) === false) { // tohle php vypisuje upozornovaci hlasky primo nad formularem //
                 echo '<ul>';
                 foreach($errors as $error) {
                   echo '<li>', $error, '</li>';            
                 }
                 echo '</ul>';
               }           
             ?>
             <form id="form-anchor" method="post" action="index.php#form-anchor">
               <div class="form-group">
                 <input type="text" name="name" class="form-control" placeholder="Your name" <?php if (isset($_POST['name']) === true) { echo 'value="', strip_tags($_POST['name']), '"'; } ?>>                                       
               </div>
               <div class="form-group">
                 <input type="email" name="email" class="form-control" placeholder="Your email" <?php if (isset($_POST['email']) === true) { echo 'value="', strip_tags($_POST['email']), '"'; } ?>>                                       
               </div>                                                                        
               <div class="form-group">
                 <textarea name="message" rows="5" class="form-control" placeholder="message...."><?php if (isset($_POST['message']) === true) { echo strip_tags($_POST['message']); } ?></textarea>                                       
               </div>
               <div class="checkbox">
                 <label>
                   <input type="checkbox" name="check">I am human
                 </label>
               </div>
               <input type="submit" name="submit" class="btn btn-secondary" value="send message">                                   
             </form>
             <?php
             }
           ?>
         </div>    
       </div>
     </div>
  </section>
</footer>
  • 写回答

4条回答 默认 最新

  • dongroufan6846 2016-08-23 12:04
    关注

    The reason why the page ends in the portfolio section instead of contacts is because the browser looks for the #fourth anchor before the images in the portfolio are loaded.

    So the browser correctly positions the page but then the contact form moves down because of the animation.

    One way to fix this is to define the height of the #imag div so that it is already the size that the images will be.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统