2012-04-16 66 views
0

我有一個表單字段quantity需要填寫。但在我的形式中,我有一些方法可以獲得價值。我不確定是否使用JavaScript來實現此目的,爲每個條目選項創建單獨的字段名稱,或完全不同的東西。在此先感謝您提供的任何見解!需要多種輸入方式的表單字段處理建議

下面是問題:「您註冊了多少人?」

選項1: 「我只能」

選項2: 「我和__其他」

方案3: 「我註冊__人以他們的名義」

我最初的想法是爲具有以下HTML(原諒格式化的粗陋):

<input type="radio" name="quantity" value="1" /> Myself only<br /> 

Myself and <select name="quantity"> 
<option value="0"></option> 
<option value="2">1 other</option> 
<option value="3">2 others</option> 
<option value="4">3 others</option> 
<option value="5">4 others</option> 
<option value="6">5 others</option> 
<option value="7">6 others</option> 
<option value="8">7 others</option> 
<option value="9">8 others</option> 
<option value="10">9 others</option> 
</select><br /> 

I'm registering <input type="text" name="quantityplus" /> people on their behalf. 

形式的其餘部分收集的聯繫人信息,然後在下一個屏幕上會顯示一組根據在此步驟中選擇的quantity註冊字段(名稱,電子郵件等)。在最後一個(quantityplus)我會在我的表單處理代碼中有一個監聽器來排除此頁面上提供的聯繫信息,並顯示該字段值中列出的實際人數(圖片爲行政助理註冊的場景她的老闆& 5人蔘加研討會,但不參加自己)。

這是解決問題的最佳方式嗎?或者我應該有一個隱藏的quantity字段,在提交表單之前使用JavaScript進行更新?如果是這樣,我該如何解決quantityplus問題?

回答

1

,我認爲你是有一個選項無線電極大混亂的形式,選擇另一個和文本第三,我會去的東西更像:

<label for="myself">Myself only <input type="radio" name="type" id="myself" value="myself" /></label> 

<label for="myselfAndOthers">Myself and others <input type="radio" name="type" id="myselfAndOthers" value="myselfAndOthers" /></label> 
<label for="myselfAndOthersQuantity">Quantity:</label><input type="text" name="quantity" id="myselfAndOthersQuantity" /> 

<label for="others">Others <input type="radio" name="type" id="others" value="others" /></label> 
<label for="othersQuantity">Quantity:</label><input type="text" name="quantity" id="othersQuantity" /> 

帶格式這應該使選項清除,那麼您的PHP可以切換三種不同類型的處理的POST值。

+0

謝謝。爲了一致性的目的,你會在第一個選項中添加一個值爲1的隱藏「數量」字段嗎? – 2012-04-16 14:23:21

+0

那麼,因爲這不會在你的處理需要(如果鍵入==我自己然後數量可以默認爲1),我會說不。無論如何,獨一無二的ID將允許您輕鬆處理JS驗證。 – Ing 2012-04-16 14:26:36

+0

好點。我想隱藏2個數量字段,直到選中該類型,然後使用jQuery來顯示它。我不知道如果這樣做仍然會$ _POST這些隱藏的變量處理器,但它很容易檢查。 – 2012-04-16 14:30:17

0
No of person for registration: <input type="text" name="quantity_per" /> 

Include Me: <input type="checkbox" name="inc_me" value="1" /> 

使用此代碼而不是許多字段。

+0

好主意,但我不介意額外的代碼,如果它有助於提高用戶體驗。在這種情況下,我發現它更容易混淆或容易出錯(就像有人離開復選框一樣) – 2012-04-16 13:16:47

+0

儘管從用戶的角度來看,您的代碼對於用戶來說很難理解,它也需要JavaScript來處理表單的響應。 – 2012-04-16 13:34:12