简体   繁体   English

序列化表格值,其中名称为blah [email]

[英]serializing form values where name is blah[email]

If I have an html form where the name values are: 如果我有一个html表单,其名称值是:

name="main[name]"
name="main[email]"
name="main[info]"

How would I go about getting all the values of the array in the form of: 我将如何以下列形式获取数组的所有值:

main : { name : 'value', email : 'value', info : 'value' }

I've tried jquery's serialize() from an older stack ( Obtain form input fields using jQuery? ) question but that solution gives me an array along the lines of 我尝试过较旧的堆栈中的jquery的serialize()使用jQuery获取表单输入字段? )问题,但该解决方案给了我一个数组

{ 'main[email]' : 'value', 'main[email]' : 'value', 'main[info]' : 'value' }

EDIT: reason i'm doing the main[email] format is because I have an extra input there for csrf which I need to differentiate from the actual input values, the final array is gonna be something like: 编辑:因为我正在做主main[email]格式是因为我有一个额外的输入csrf我需要区别于实际的输入值,最终的数组将是这样的:

  [ csrf: '', main : { name : 'value', email : 'value', info : 'value' } ]

this way I can just use main values. 这样我就可以使用main值了。

Why not just set your fields like this? 为什么不设置这样的字段?

 name="name"
 name="email"
 name="info"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM