Stephan Hovnanian
Stephan Hovnanian

Reputation: 189

Need Suggestion for form field handling with multiple input methods

I have a form field called quantity that needs to be filled out. But in my form I have a couple ways I'd like to get the value. I'm not sure whether to approach this with JavaScript, create separate field names for each entry option, or something totally different. Thanks in advance for any insight you can give me on this!

Here's the question: "How many people are you registering?"

Option 1: "Myself Only"

Option 2: "Myself and __ Others"

Option 3: "I'm registering __ people on their behalf"

My initial thought was to have the following HTML (forgive the crudeness of formatting):

<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.

The rest of the form gathers contact information, and then on the next screen would display a set of registration fields (name, email etc) based on the quantity selected in this step. On that last one (quantityplus) I'd have a listener in my form processing code to exclude the contact info provided on this page and display the actual # of people listed in that field's value (picture a scenario where an administrative assistant would be registering her boss & 5 others for a seminar, but is not attending herself).

Would this be the optimal way to approach the problem? Or should I have a hidden quantity field that gets updated using JavaScript before the form is submitted? If so, how do I account for the quantityplus issue?

Upvotes: 0

Views: 119

Answers (2)

Ingmar Boddington
Ingmar Boddington

Reputation: 3500

I think you are confusing the form greatly by having a radio for one option, select for another and text for the third, I would go for something more like:

<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" />

With formatting this should make the options clear, then your PHP can just switch on the type POST value for the three different types' handling.

Upvotes: 1

Vipin Jain
Vipin Jain

Reputation: 1402

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

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

Use this code instead of so many fields.

Upvotes: 0

Related Questions