2014-09-26 48 views
0

由於某些原因,點擊提交後,我的頁面只會重定向到一個空的表單。我似乎無法弄清楚原因。我唯一的猜測是,它不承認「提交」是真實的,只是通過else子句返回自己。但是,我已將表單的操作轉換爲已定義的網址(例如http://google.com),並將其發送給目標。任何援助非常感謝。爲什麼我的表單重定向到自己而不是重定向到指定的目標?

編輯:我已經能夠可靠地顯示,這是我的表單標記行爲不正確的行爲值。

我執行了以下測試:我可以輸入任意一個條件來查詢if/else語句,並將該值回顯到條件之下。但是,如果我嘗試回顯上面的表單,它將不會返回任何內容,但是我輸入的表單的值將在表單上回顯(例如,conferenceName爲$ _POST ['conferenceName']將在表單上回顯)。

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Conference Registration [This Page Not Yet Active]</title> 
     <link rel="stylesheet" type="text/css" href="cmxform.css"> 
    </head> 
    <body> 
     <form method="post" action="<?php echo $action; ?>" class="cmxform"> 
     <fieldset> 
      <legend>Example Conference Registration</legend> 
      <ol style="list-style-type: none;"> 
       <li> 
        <label for="conferenceName">Applicant's Name<em>*</em></label> <input name="conferenceName" type="text"> 
       </li> 
       <li> 
        <label for="conferenceAgencySchool">Agency School<em>*</em></label> <input name="conferenceAgencySchool" type="text"> 
       </li> 
       <li> 
        <label for="conferenceAgencyAddress">Agency Address<em>*</em></label> <input name="conferencePhysicalAddress" type="text"> 
       </li> 
       <li> 
        <label for="conferenceCity">City<em>*</em></label> <input name="conferenceCity" type="text"> 
       </li> 
       <li> 
        <label for="conferenceState">State<em>*</em></label> <input name="conferenceState" type="text"> 
       </li> 
       <li> 
        <label for="conferenceZip">Zip<em>*</em></label> <input name="conferenceZip" type="text"> 
       </li> 
       <li> 
        <label for="conferencePhone">Phone<em>*</em></label> <input name="conferencePhone" type="text"> 
       </li> 
       <li> 
        <label for="conferenceExtension">Extension</label> <input name="conferenceExtension" type="text"> 
       </li> 
       <li> 
        <label for="conferenceNumberOfAttendees">Number of Attendees<em>*</em></label> <input name="conferenceNumberOfAttendees" type="text"> 
       </li> 
       <li> 
        <label for="conferencePointOfContactName">P.o.C. Name<em>*</em></label> <input name="conferencePointOfContactName" type="text"> 
       </li> 
       <li> 
        <label for="conferencePointOfContactPhone">P.o.C. Cell Phone<em>*</em></label> <input name="conferencePointOfContactPhone" type="text"> 
       </li> 
       <li> 
        <label for="conferencePointOfContactEmail">P.o.C. Email<em>*</em></label> <input name="conferencePointOfContactEmail" type="text"> 
       </li> 
       <li> 
        <label for="conferenceAdditionalAttendeeInfo">Additional Attendee(s) Info</label> 
        <textarea name="conferenceAdditionalAttendeeInfo" style="height: 100px; width: 90%; max-width: 90%; min-width: 90%;" wrap="soft"></textarea> 
       </li> 
      </ol> 
      <hr> 
      <legend>Method of Payment<em>*</em></legend> 
      <ol style="list-style-type: none;"> 
       <li> 
        <label><input name="payment" type="radio" value="Online">Online</label> 
       </li> 
       <li> 
        <label><input name="payment" type="radio" value="At The Door"> At the Door</label> 
       </li> 
       <li> 
        <label>Invoice # (If Using Invoice)</label><input name="invoiceNumber" type="text"> 
       </li> 
      </ol> 
      <hr> 
     </fieldset><input name="submit" type="submit" value="Submit Application"> 
     </form> 
     <?php 
     if (isset($_POST["submit"]) && 
      (!empty($_POST["conferenceName"])) && 
      (!empty($_POST["conferenceAgencySchool"])) && 
      (!empty($_POST["conferencePhysicalAddress"])) && 
      (!empty($_POST["conferenceCity"])) && 
      (!empty($_POST["conferenceState"])) && 
      (!empty($_POST["conferenceZip"])) && 
      (!empty($_POST["conferencePhone"])) && 
      (!empty($_POST["conferenceNumberOfAttendees"])) && 
      (!empty($_POST["conferencePointOfContactName"])) && 
      (!empty($_POST["conferencePointOfContactPhone"])) && 
      (!empty($_POST["conferencePointOfContactEmail"])) 
     ) 
     { 
     $action="http://example.net/form-submit.php"; 
     } 
     else 
     { 
     $action = '"<?php echo $_SERVER["PHP_SELF"]; ?>"'; 
     } 
     ?> 
    </body> 
</html> 

按照您親切的人提供的建議後輸出。

<!DOCTYPE html> 
<!-- saved from url=(0044)http://example.net/conference-registration.php --> 
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
     <title>Conference Registration [This Page Not Yet Active]</title> 
     <link rel="stylesheet" type="text/css" href="./Conference Registration [This Page Not Yet Active]_files/cmxform.css"> 
    </head> 
    <body> 
     <form method="post" action="" class="cmxform"> 
     <fieldset> 
      <legend>Example Conference Registration</legend> 
      <ol style="list-style-type: none;"> 
       <li> 
        <label for="conferenceName">Applicant's Name<em>*</em></label> <input name="conferenceName" type="text"> 
       </li> 
       <li> 
        <label for="conferenceAgencySchool">Agency School<em>*</em></label> <input name="conferenceAgencySchool" type="text"> 
       </li> 
       <li> 
        <label for="conferenceAgencyAddress">Agency Address<em>*</em></label> <input name="conferencePhysicalAddress" type="text"> 
       </li> 
       <li> 
        <label for="conferenceCity">City<em>*</em></label> <input name="conferenceCity" type="text"> 
       </li> 
       <li> 
        <label for="conferenceState">State<em>*</em></label> <input name="conferenceState" type="text"> 
       </li> 
       <li> 
        <label for="conferenceZip">Zip<em>*</em></label> <input name="conferenceZip" type="text"> 
       </li> 
       <li> 
        <label for="conferencePhone">Phone<em>*</em></label> <input name="conferencePhone" type="text"> 
       </li> 
       <li> 
        <label for="conferenceExtension">Extension</label> <input name="conferenceExtension" type="text"> 
       </li> 
       <li> 
        <label for="conferenceNumberOfAttendees">Number of Attendees<em>*</em></label> <input name="conferenceNumberOfAttendees" type="text"> 
       </li> 
       <li> 
        <label for="conferencePointOfContactName">P.o.C. Name<em>*</em></label> <input name="conferencePointOfContactName" type="text"> 
       </li> 
       <li> 
        <label for="conferencePointOfContactPhone">P.o.C. Cell Phone<em>*</em></label> <input name="conferencePointOfContactPhone" type="text"> 
       </li> 
       <li> 
        <label for="conferencePointOfContactEmail">P.o.C. Email<em>*</em></label> <input name="conferencePointOfContactEmail" type="text"> 
       </li> 
       <li> 
        <label for="conferenceAdditionalAttendeeInfo">Additional Attendee(s) Info</label> 
        <textarea name="conferenceAdditionalAttendeeInfo" style="height: 100px; width: 90%; max-width: 90%; min-width: 90%;" wrap="soft"></textarea> 
       </li> 
      </ol> 
      <hr> 
      <legend>Method of Payment<em>*</em></legend> 
      <ol style="list-style-type: none;"> 
       <li> 
        <label><input name="payment" type="radio" value="Online">Online</label> 
       </li> 
       <li> 
        <label><input name="payment" type="radio" value="At The Door"> At the Door</label> 
       </li> 
       <li> 
        <label>Invoice # (If Using Invoice)</label><input name="invoiceNumber" type="text"> 
       </li> 
      </ol> 
      <hr> 
     </fieldset><input name="submit" type="submit" value="Submit Application"> 
     </form> 

<script type="text/javascript" async="" src="./Conference Registration [This Page Not Yet Active]_files/si.js"></script></body></html> 
+0

靠近底部的那一行,應該不是'$ action = $ _SERVER ['PHP_SELF'];'? – castis 2014-09-26 04:36:26

+0

粘貼呈現的html代碼。 – Maigret 2014-09-26 04:42:35

+0

在建議實施後添加了HTML輸出。 – Nick 2014-09-26 04:46:17

回答

1

你包圍在引號內PHP迴音是下面這行做的錯誤的方式:

$action = '"<?php echo $_SERVER["PHP_SELF"]; ?>"'; 

此代碼將只返回""

將其更改爲

$action = $_SERVER["PHP_SELF"]; 
0

您可以使用 「#」 或行動變量分配$ _ SERVER [ 「PHP_SELF」]。

相關問題