2015-12-18 55 views
2

我有一個功能完善的聯繫表單,並在提交時顯示「謝謝」信息。唯一的問題是,感謝消息顯示在表單上方,因此當用戶單擊該消息時發送消息並不明顯。聯繫表格謝謝您回到頁首

我的形式是在這裏:

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 = '[email protected]'; 
     $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("[email protected]", $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> 
+0

在JavaScript中,您可以爲包含'document.scrollTop = 0'的提交按鈕設置一個onclick事件。我把這個作爲評論,因爲JavaScript不是你的標籤之一。如果你想我可以寫更詳細的答案。 – Sam

回答

1

爲什麼不把你的形式的ID,然後直接到錨表單中的作用:

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

這基本上會提交您的形式,並刷新你的網址爲:

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

一它應該把你帶到你想要的地方,它在我設定的一個簡單的測試中工作。

或者,我想,而不是形式的ID設置爲"my-form",你可以可以設置您的<p>標籤包含您的確認消息,像"form-confirmation-message" ID和表單的操作設置爲action="#form-confirmation-message"

這可能會是最好的選擇,因爲它會使你的信息正確,而不是形式,這正好接近你的信息。

+0

這正是我所需要的,謝謝! – ndumanov

+0

很高興它的作品!您的網站看起來不錯! –

+0

非常感謝,我相當新的編碼,這意味着很多。如果我能代表你,我會! – ndumanov