获取多页/多部分表单中的所有 html 表单数据
我有一个多页表单,我需要从表单中获取所有数据。我知道我可以手动执行此操作,但我想要一种更动态的方法。是的,如果可能的话,请仅使用 javascript 给我一个答案。
编辑... 如果有些含糊,我很抱歉。 我想做的是向用户呈现他输入的所有数据,所以我认为这是客户端而不是服务器端。另外,我现在已经安装了PHP。所以,如果有 PHP 的方式,那也可以。
它是多页的,因为用户会从不同的网页跳转,因为如果用户在一页中输入所有数据,时间会很长。嗯……一个例子是纳税申报表。或者某种人口普查。这就是表格的长度和我必须获取的数据量。所以,我想知道一种动态的方法。
我还没说完。感谢下面的评论。我已经尝试过,其中一些是有益的。
I have a multi-paged forms and I need to get all the data from the forms. I know I can do this manually but I want a more dynamic approach. Yeah, if possible, please give me an answer using javascript only.
Edit...
I'm sorry if it was somewhat vague.
What I want to do is to present to the user all the data he entered, so i think this is client-side not server-side. Also, I have installed PHP now. So, if there's a PHP way, then that's also ok.
It's multi-paged because the user will jump from different web-pages because it will be very long if the user will input all the data in just one page. Hmmm... an example would be a tax-filing form. Or some kind of census. That's how long the form is and the amount of data I have to get. So, I want to know a dynamic way to do it.
I'm still not finished. Thanks to the comments below. I have tried them and some are beneficial.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试一下
它会选择执行页面上的所有“form”标签,然后将序列化数据发布到“destination_site.php”
在您的脚本站点上,您可以使用
$_POST['name_of_input_element']
如果您想访问客户端站点上的输入元素,则无需发布它们。
使用它来访问您网站的所有形式的所有输入元素
Try this
It selects all "form" Tags on the page it is executed and then post the serialized data to "destination_site.php"
On your script site, you can access them with
$_POST['name_of_input_element']
If you want to access the input elements on the client site, you dont need to post them.
Use this to access all input elements of all forms of your site
好吧,我想我已经解决了我的问题。我就是这样做的。
首先,我没有使用多个页面,而是使用隐藏的 div,并在用户单击下一页时使其可见,并使当前表单隐藏。
然后,我了解到我可以使用以下代码访问所有数据:
var value = document.forms[formname].elements[index].value;
并将其放入循环中
,然后通过以下方式处理所有内容:
感谢您的所有帮助。
Ok, I think I have solved my problem. This is how I did it.
First, instead of using multiple pages, I used hidden divs and make it visible as the user clicks the next page and make the present form hidden.
Then, I learned that I can access all the data by using this code:
var value = document.forms[formname].elements[index].value;
and put it inside a loop
and then process it all by:
Thanks for all the help btw.
使用 jquery 的 serialize 您可以从表单中获取每个字段,然后使用 ajax
with jquery's serialize you can get every field from a form and then send it to a php script with ajax