如何处理许多同名的输入字段,并将其发布到PHP?
假设我有一个HTML结构,看起来像这样。每个左上下文字段和右上下文字段都是相关的,在后端,应该可以将左上下文字段链接到右上下文字段如何处理许多同名的输入字段,并将其发布到PHP?,php,jquery,data-oriented-design,Php,Jquery,Data Oriented Design,假设我有一个HTML结构,看起来像这样。每个左上下文字段和右上下文字段都是相关的,在后端,应该可以将左上下文字段链接到右上下文字段 在HTML表单中,发送数组的方式是使用括号 比如说 name="values[]" name="values[]" 像这样 <form name = 'vals_form' action = 'php_page.php' method = 'post'> <table> ... <!-- Your all code -
在HTML表单中,发送数组的方式是使用括号 比如说
name="values[]"
name="values[]"
像这样
<form name = 'vals_form' action = 'php_page.php' method = 'post'>
<table>
... <!-- Your all code -->
<tr>
<td>
<input type="text" class="left-context-field" value="First left value" name="values[]">
</td>
<td>
<input type="text" class="right-context-field" value="First right value" name="values[]">
</td>
</tr>
...
<input type = 'submit' value = 'Post Values' />
</table>
</form> <!--and close the form tag-->
<form name = 'vals_form' action = 'php_page.php' method = 'post'>
<table>
... <!-- Your all code -->
<tr>
<td>
<input type="text" class="left-context-field" value="First left value" name="values[]">
</td>
<td>
<input type="text" class="right-context-field" value="First right value" name="values[]">
</td>
</tr>
...
<input type = 'submit' value = 'Post Values' />
</table>
</form> <!--and close the form tag-->
我已经编辑了meda的答案,但他不同意编辑,所以我再次在这里发布。
在HTML表单中,发送数组的方式是使用括号 比如说
name="values[]"
name="values[]"
像这样
<form name = 'vals_form' action = 'php_page.php' method = 'post'>
<table>
... <!-- Your all code -->
<tr>
<td>
<input type="text" class="left-context-field" value="First left value" name="values[]">
</td>
<td>
<input type="text" class="right-context-field" value="First right value" name="values[]">
</td>
</tr>
...
<input type = 'submit' value = 'Post Values' />
</table>
</form> <!--and close the form tag-->
<form name = 'vals_form' action = 'php_page.php' method = 'post'>
<table>
... <!-- Your all code -->
<tr>
<td>
<input type="text" class="left-context-field" value="First left value" name="values[]">
</td>
<td>
<input type="text" class="right-context-field" value="First right value" name="values[]">
</td>
</tr>
...
<input type = 'submit' value = 'Post Values' />
</table>
</form> <!--and close the form tag-->
然后如何将这些表单发布到PHP?您需要在
表
周围创建一个表单
标记,并需要将该表单
发布到按钮上。从语义HTML的角度来看,单击@MubinKhalid,是最好包装整个表,还是只包装所有行?我已经编辑了meda的答案,但是他不同意这个编辑,所以我发布了一个新的答案。你得把整张桌子都包起来。但是现在如何将表单发送到PHP?表单的属性操作
指定当单击发布值
按钮时,此表单
应该转到哪里。在这个场景中,它将发布到action='php\u page.php'
--php\u page.php
。确保您已在表单中添加了一个按钮,以使用属性type=submit
发送此表单
,否则您必须使用jQuery
将内容发布到后端