加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 22:19:24 所属栏目:PHP教程 来源:网络整理
导读:我想在提交按钮单击上发布此html表. 01 – 我想在php代码(服务器端)中检索此表的数据 02 – 我也想在另一页上显示这个表. 我正在使用 PHP,JQuery 我有表格标签中有很多行的html表. form id="frm_test" class="form-vertical" method="post" table id="mytabl
我想在提交按钮单击上发布此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的答案中,但没有指出.(添加因为最近的搜索引导我这个)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读