php - 联系表 谢谢 页面顶部

标签 php html css forms contacts

我有一个功能齐全的联系表单,在提交时会显示“谢谢”消息。唯一的问题是感谢消息显示在表单上方,因此当用户单击它时,消息是否已发送并不明显。

我的表格在这里:

http://impressify.co/business-writing.php

如何才能让当我点击提交按钮时页面滚动到顶部然后显示联系信息?我不想让用户知道消息已成功发送。

我的代码如下:

 <?



 if($_SERVER['REQUEST_METHOD'] == "POST")  {                                                            
     $allowedExts = array("gif", "jpeg", "jpg", "png", "doc", "pdf", "docx",         
 "jpg", "docx", "odt", "txt", "msg", "csv", "pps", "ppt", "pptx", "xml", 
 "tar", "m4a", "mp3", "wav", "wma", "mp4", "mov", "flv", "exe");


      for ($i = 1; $i <= 2; $i++) {
          $temp = explode(".", $_FILES["attach".$i]["name"]);
          $extension = end($temp);
          if (in_array($extension, $allowedExts)) {
              move_uploaded_file($_FILES["attach".$i]["tmp_name"],
  "upload/" .$_POST["firstname"]."-".$_FILES["attach".$i]["name"]);
          }
      }

      $to = 'myemail@gmail.com';
      $subject = 'Business Writing Request from      
  '.$_POST["firstname"].$_POST["email"];
      $message = $_POST["message"]."\n\n\n Attachments: ".$_FILES["attach1"]  
  ["firstname"]." ".$_FILES["attach2"]["firstname"]." 
  ".$_FILES["attach3"]["firstname"];
      $firstname=$_REQUEST['firstname'];
      $companyname=$_REQUEST['companyname'];
      $email=$_REQUEST['email'];

      if (($firstname=="")||($email=="")||($message=="")) 
      { 
         echo "<strong><p class =greentip>A first name, message, and email are    
   required, please fill <a href=/business-writing.php>the form</a>   
   again.</p></strong><br>"; 
      } 
      else{ 
          mail("n.dumanov@gmail.com", $subject, $message, $email);
          echo "<strong><p>Your free consultation request has been received!     
  Expect a detailed response within the next 24 hours!</p></strong>"; 
      }  

  }
  ?>

  <form  action="" method="post" enctype="multipart/form-data">                       
 <div class="row uniform 50%">

                            <div class="6u 12u(mobilep)">                                    

<input name="firstname" type="text" value="" placeholder="Name"><br>
</div>

     <div class="6u 12u(mobilep)">

<input name="companyname" type="text" value="" placeholder="Company Name"><br>
     </div>

     <div>
<input name="email" type="text" value="" placeholder="Email"><br> 
 </div>
 </div>
<div class="row uniform 50%">

                            <div class="12u">
<textarea name="message" rows="7" cols="30" placeholder="Give us a general sense of the kind of writing you or your ogranization needs."></textarea><br> 
</div>

                        </div>

     <br><br>
    <center><input class type="submit" value="submit"></center> <br>
     </form>

最佳答案

为什么不设置表单的 ID,然后直接指向表单操作中的 anchor :

<form action="#my-form" method="post" enctype="multipart/form-data" id="my-form">

这基本上会提交您的表单并重新加载您的 URL 为:

http://impressify.co/business-writing.php#my-form

它应该会把你带到你想去的地方,它在我设置的一个简单测试中起作用了。

或者我想不是将表单的 ID 设置为 "my-form"你可以设置你的 ID <p>包含您的确认消息的标签,类似于 "form-confirmation-message"并将表单的操作设置为 action="#form-confirmation-message"

这可能是最好的选择,因为它会让您直接看到您的消息,而不是表格,它就在您的消息旁边。

关于php - 联系表 谢谢 页面顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34346550/

相关文章:

javascript - 单击选项卡时 Bootstrap 隐藏工具提示

css - Rails application.css.scss 不知道其他正在使用的 scss 文件?

php mysql 在 html 页面上打印值的问题

php - 从表中删除嵌套类别

php - session 过期后用帖子重定向

css - <div> 高度不随内容扩展。设置 "height: auto"删除边框

javascript - 如何使用Javascript在两个页面之间传递数据

css - SVG - 为什么我的 SVG 周围有边距,即使我没有设置边距?

php - 构建高效的 PHP/MySQL 程序时应遵循哪些经验法则?

css - 不同的背景渐变