如何在单个HTML表单中提交多个值? [英] How to Submit Multiple Values in a single HTML Form?
本文介绍了如何在单个HTML表单中提交多个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个HTML表单:
So I have a HTML form:
<html>
<body>
<script>history.pushState('', '', '/')</script>
<form action="http://myserver.com" method="POST">
<input type="hidden" name="Id" value="83" />
<input type="hidden" name="url" value="http://example.com/" />
<input type="submit" value="Submit request" />
</form>
<script>
document.forms[0].submit();
</script>
</body>
</html>
如您所见,这是为<input type="hidden" name="Id" value="83" />
提交操作,这意味着它是为与ID号83相关联的属性提交的,我希望为多个ID值(即1-100)提交操作. ?如果可以,该怎么办?
As you can see this is submitting the action for <input type="hidden" name="Id" value="83" />
meaning it's submitted for the attribute associated with ID number 83, I'm wanting the action to be submitted for multiple ID values, i.e. 1 - 100. Is this possible? If so how can it be done?
推荐答案
我认为您想做这样的事情
I assume you want to do something like this
<html>
<body>
<script>history.pushState('', '', '/')</script>
<form action="http://myserver.com" method="POST">
<input type="hidden" name="Id[]" value="83" />
<input type="hidden" name="Id[]" value="85" />
<!-- you can add as many as input here for id if you want -->
<input type="hidden" name="url" value="http://example.com/" />
<input type="submit" value="Submit request" />
</form>
<script>
document.forms[0].submit();
</script>
</body>
</html>
发布此表单后,在服务器端,您可以将$ _POST ['id']作为数组并对其进行操作.
After this form is posted, on the server side you can get $_POST['id'] as an array and playing around with it.
这篇关于如何在单个HTML表单中提交多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文