2013-10-24 142 views
0

我正在本地工作,我正在嘗試向它添加聯繫表單。PHP URL重定向

我已經添加了一個簡單的表單:http:localhost:8888/testsite/contact.php,當用戶點擊提交按鈕時,我希望他們被重定向到另一個頁面上,並顯示一條消息。我希望用戶在提交表單後訪問的頁面:contact_message.php。

我已經創建了這兩個文件,它們都在那裏顯示確定URL- http:localhost:8888/testsite/contact.php和http:localhost:8888/testsite/contact-message.php,但是表單不是因爲當你點擊提交url更改爲:http:localhost:8888/testsite/contact.php/contact-message.php時,如果它顯示contact-message.php內容,它會很好,但事實並非如此。

脫穎而出形式的代碼是:

<form method="post" action="contact-message.php"> 
    <table> 
     <tr> 
      <th> 
       <label for="name">Name</label> 
      </th> 
      <td> 
       <input type="text" name="name" id="name"> 
      </td> 
     </tr> 
     <tr> 
      <th> 
       <label for="email">Email</label> 
      </th> 
      <td> 
       <input type="text" name="email" id="email"> 
      </td> 
     </tr> 
     <tr> 
      <th> 
       <label for="message">Message</label> 
      </th> 
      <td> 
       <textarea type="text" name="message" id="message"></textarea> 
      </td> 
     </tr> 

    </table> 

    <input type="submit" value="Send"> 

</form> 

沒有任何人有任何想法...?

感謝

+0

你肯定接觸,message.php腳本實際上在工作嗎?語法錯誤可能會在執行ANY輸出之前終止腳本,留下空白瀏覽器。例如自己做一些基本的調試... –

回答

1

您需要在表單操作中向正確的文件添加完整路徑或相對路徑。目前,您正在將表單提交給當前網址以及contact-message.php。相反,嘗試...

<form method="post" action="http:localhost:8888/testsite/contact-message.php"> 

或者乾脆..

<form method="post" action="/contact-message.php"> 

告訴它使用基本URL + /contact-message.php

+0

如果我使用:

然後,使url http:// localhost:8888/contact-message .php'而不是'http:// localhost:8888/testsite/contact-message.php' – PK333

+1

我無法知道您的基本網址是localhost:8888還是localhost:8888/testsite,因爲它們都可以配置。在這種情況下,您可以將其更改爲action =「/ testsite/contact-message.php」 –

0

嘗試替換形式標籤:

<form method="post" action="./contact-message.php"> 

然後這將調用contact-message.php文件位於相同的文件夾中。該點是從當前位置開始的相對路徑的開始