dongzhina7098 2013-11-05 00:28
浏览 55
已采纳

尝试发布包含多个与数组同名的字段的表单

i am trying to post a form with fields that act like a table entries

I think it would be best if i give an example:

<form method="post">
    <table>
        <tr>
            <td><label>Name:</label></td>
            <td><input type="text" name="appsDetails[name]" placeholder="Enter name" value=""/></td>
            <td><label>ID:</label></td>
            <td><input type="text" name="appsDetails[id]" placeholder="Enter id" value=""/></td>
            <td><label>Token:</label></td>
            <td><input type="text" name="appsDetails[token]" placeholder="Enter token" value=""/></td>
        </tr>

        <tr>
            <td><label>Name:</label></td>
            <td><input type="text" name="appsDetails[name]" placeholder="Enter name" value=""/></td>
            <td><label>ID:</label></td>
            <td><input type="text" name="appsDetails[id]" placeholder="Enter id" value=""/></td>
            <td><label>Token:</label></td>
            <td><input type="text" name="appsDetails[token]" placeholder="Enter token" value=""/></td>
        </tr>

        <tr>
            <td><label>Name:</label></td>
            <td><input type="text" name="appsDetails[name]" placeholder="Enter name" value=""/></td>
            <td><label>ID:</label></td>
            <td><input type="text" name="appsDetails[id]" placeholder="Enter id" value=""/></td>
            <td><label>Token:</label></td>
            <td><input type="text" name="appsDetails[token]" placeholder="Enter token" value=""/></td>
        </tr>


    </table>
</form>

You can also check: fiddle example

When the above example get submitted i only get the last row in the table.

My question is. is there a way to do it like array within array ? if that make sense

I am trying to avoid doing something like name[]. id[], token[].

  • 写回答

1条回答 默认 最新

  • duanlun2827 2013-11-05 00:34
    关注

    Sure you can, simply use an empty [], everytime this one is encountered, it is considered as a new sibling

    <tr>
                <td><label>Name:</label></td>
                <td><input type="text" name="appsDetails[][name]" placeholder="Enter name" value=""/></td>
                <td><label>ID:</label></td>
                <td><input type="text" name="appsDetails[][id]" placeholder="Enter id" value=""/></td>
                <td><label>Token:</label></td>
                <td><input type="text" name="appsDetails[][token]" placeholder="Enter token" value=""/></td>
            </tr>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP