如何在单个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.