2016-01-16 48 views
-1

我有一個表格是這樣的:登記表使用數組但在表單值未提交

<form class="registration-form" name="applicationForm" action="<?=$_SERVER['PHP_SELF']?>" method="get"> 
        <div class="form-top"><h3 class="col-md-12 col-md-offset-4">Application for employment</h3> </div> 

        <div class="col-md-12 col-sm-12 col-lg-6"> 

         <div class="col-md-12"> 
          <div class="form-group"> 
           <label for="inputFirstName">First Name</label> 
           <input type="text" class="form-control required" id="inputFirstName" placeholder="First Name" name="driver[first_name]" /> 
          </div> 
          <div class="form-group"> 
           <label for="inputMiddle">Middle Initial</label> 
           <input type="text" class="form-control" id="inputMiddle" placeholder="Middle Initial" name="driver[middle]" /> 
          </div> 
          <div class="form-group"> 
           <label for="inputLastName">Last Name</label> 
           <input type="email" class="form-control required" id="inputLastName" placeholder="Last Name" name="driver[last_name]" /> 
          </div> 
          <div class="form-group"> 
           <label for="inputDob">Date of Birth</label> 
           <input type="email" class="form-control required datepicker" id="inputDob" placeholder="MM/DD/YYYY" name="driver[dob]" /> 
          </div> 

但是當我嘗試打提交按鈕後顯示的值,也不會提交和將不顯示值。我有這樣的事情顯示的值:

$form_names = array_keys($_GET); 
$form_values = array_values($_GET); 

if(isset($_GET["submit"])) 

{ 

     echo "<h3>Your Input:</h3>"; 
     for ($i = 0; $i < sizeof($_GET); $i++) { 
     echo "<p>".$form_names[$i]." = " . $form_values[$i] . "</p>"; 




     } 
} 

請告訴我什麼是丟失或錯誤的東西在我的代碼,因爲它不會提交併顯示值。它在註冊後也不會發送電子郵件。

+0

好這永遠不會發生'如果(isset($ _ GET [ 「提交」])){...}'你似乎沒有結束''標籤。 *「我有一個這樣的表格:」* - 你是什麼意思「像這樣」。類似的東西,還是那個? –

+0

*「註冊後它也不會發送電子郵件。」* - 在您的發佈代碼中沒有看到任何郵件功能。 –

+0

然後姓氏和DOB是'電子郵件'類型。代碼中的錯誤太多。 –

回答

2

您發佈的代碼有很多錯誤。

首先,如果您的代碼沒有關閉</form>標記,那麼您需要添加它。

您還沒有爲if(isset($_GET["submit"]))設置名稱屬性,例如帶有匹配名稱屬性的提交按鈕,因此該條件語句內沒有任何內容會觸發。

<input type = "submit" name = "submit" value = "Submit"> 

你還需要將driver屬性添加到$_GET陣列。

$form_names = array_keys($_GET['driver']); 
$form_values = array_values($_GET['driver']); 

,並在循環也:

for ($i = 0; $i < sizeof($_GET['driver']); $i++) 

此外,無論您Last NameDate of Birth輸入端分別使用<input type="email"代替textdate

有人試圖將數據輸入到電子郵件輸入和現在的方式,它會失敗,並在日期輸入相同。 「

」它在註冊後也不會發送電子郵件。「

我在您的發佈代碼中沒有看到任何郵件功能,因此您需要對此進行排序。

請教關於mail()手動,如果這是你使用的是什麼:

添加error reporting添加到您的文件的頂部,這將有助於查找錯誤。

<?php 
error_reporting(E_ALL); 
ini_set('display_errors', 1); 

// Then the rest of your code 

旁註:顯示錯誤應該只在分期完成,並且從不生產。


腳註:

我建議你不要使用GET,但POST,因爲它似乎是你可以(通過網絡)發送敏感信息。使用POST更安全。

因此,您可以將$_GET的所有實例更改爲$_POST,包括表單方法,您將得到相同的結果。從我的回答

樣品結果:

 
first_name = John 

middle = Q 

last_name = Public 

dob = 01/01/1984 
+0

非常感謝Fred :)我會嘗試你的建議。 – loenex

+0

@loenex不客氣。 –