需要建议使用多种输入法处理表单字段


Need Suggestion for form field handling with multiple input methods

我有一个名为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问题?

我认为您通过为一个选项使用收音机,为另一个选项选择并为第三个选项选择文本而极大地混淆了形式,我会选择更像这样的东西:

<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 可以打开 type POST 值来处理三种不同类型的处理。

No of person for registration: <input type="text" name="quantity_per" />
Include Me: <input type="checkbox" name="inc_me" value="1" />

使用此代码而不是这么多字段。