php – 使用via表单提交html表数据(post)

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 使用via表单提交html表数据(post)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在提交按钮单击上发布此htML表.

01 – 我想在PHP代码(服务器端)中检索此表的数据
02 – 我也想在另一页上显示这个表.

我正在使用

PHP,jquery

我有表格标签中有很多行的html表.

<form id="frm_test" class="form-vertical" method="post">
  <table id="mytable">
    <tr>
      <td>
        <input tyPE="text"  name="color_1" value="" />
      </td>
      <td>
        <input type="text"  name="color_2" value="" />
      </td>
      <td>
        <input type="text"  name="color_3" value="" />
      </td>
      <td>
        <input type="text"  name="color_4" value="" />
      </td>
    </tr>
    ......
    ......
    ......
    ......
    .....
  </table>

  <input type="submIT"  name="submit" value="submit" />
</form>

===========

每行有4个输入字段(每行4个单元格).和表中的一百行.因此,如果我通过PHP代码中的名称获取值,那么我必须编写大量代码以获得100(行)* 4(输入字段)= 400输入.所以我的问题是“实现这一目标的最佳途径是什么

解决方法

由于您尝试向后端提交具有相同“name”属性的多行输入/选择,因此您需要在这些输入(表行)中的名称值末尾添加方括号[].

<form>
<input type="number" name="exampleVAR" />
<table>
  <tr>
    <td><input type="text" name="color_1[]" /></td>
    <td><input type="text" name="color_2[]" /></td>
  </tr>
  <tr>
    <td><input type="text" name="color_1[]" /></td>
    <td><input type="text" name="color_2[]" /></td>
  </tr>
<table>
<input type="submit" />
</form>

这告诉浏览器为该name属性创建一个数组.

PHP中,将其读作$_POST [‘color_1’] [0]和$_POST [‘color_2’] [0],并根据需要循环播放.

括号在Phil Bailey的答案中,但没有指出.(添加因为最近的搜索引导我这个)

脚本宝典总结

以上是脚本宝典为你收集整理的php – 使用via表单提交html表数据(post)全部内容,希望文章能够帮你解决php – 使用via表单提交html表数据(post)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。