开发者

A series of groups of inputs that can be added to and removed from - how do I keep order?

I'm stuck trying to work out the be开发者_开发知识库st possible way to approach this.

Basically, I have in interface that administrates form inputs. That is, this interface is in charge of the inputs that are displayed and utilized on another interface. I have multiple input types - text input, textarea, select, etc. So, from an administrator point of view, almost all of the controls are text inputs, but for each 'user-side' input, that's several text inputs, the number of which varies depending on the 'user-side' input.

For example, the administration fields for a single text input are: name, id, and description. For a textarea, they're the same. For a select input, I might have name, id, description, and then a series of 'value' and 'title' inputs for the select's options.

So here's where I'm stuck. I need to work out the best way to assign names to these inputs in the administration side so that when I click 'save', I can group the relevant inputs together.

Right now the form would just be a series of inputs like this:

input, text [name for input 1]
input, text [id for input 1]
input, text [description for input 1]

input, text [name for input 2]
input, text [id for input 2]
input, text [description for input 2]

input, text [name for field 3]
input, text [id for field 3]
input, text [description for field 3]
input, text [option value 1 for select field 3]
input, text [option title 1 for select field 3]
input, text [option value 2 for select field 3]
input, text [option title 2 for select field 3]
input, text [option value 3 for select field 3]
input, text [option title 3 for select field 3]

input, text [name for textarea 4]
input, text [id for textarea 4]
input, text [description for textarea 4]

Would it perhaps be possible to delineate 'groups' of inputs using a hidden 'input_type' field (probably necessary anyways)?

I hope that made some sense. I'm basically looking for a way to delineate/group inputs from a single form POST set.


You can create PHP array structures with your form names like so.

<input name="form[name][]" />
<input name="form[name][]" />
<input name="form[name][]" />

Would yield:

$_POST['form']['name'][0]
$_POST['form']['name'][1]
$_POST['form']['name'][2]

You should be able to work out some form of structure that will work for your needs.


Be wary of over-engineering. HTML is simple enough not to attempt dissecting form inputs. But if you have a good reason to do this, why should there be three or four inputs for each user-interface form element? Define a convention and have the admin use it. Something like:

text, firstName, firstName, Enter your first name
area, address, , Type in your address
list, gender, gender, Sex, 0|Male, 1|Female

On the server explode is your friend, and it would be much easier both for the admin to fill in values and for you to parse the properties.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜