我将如何创建HTML表单这个数组结构? [英] How would I create this array structure in an HTML form?

查看:167
本文介绍了我将如何创建HTML表单这个数组结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的HTML表单,正在在MySQL数据库中动态生成一个表。

I have the following HTML form, which is being generated dynamically from a table in a MySQL database.

<form method="post" name="chapters" action="ChaptersUpdate.php">
<input type='text' name='id' value='{$row['id']}'>
<input type='text' name='name' value='{$row['name']}'>
<input type='password' name='password' value={$row['password']};>
<input type='submit'>
</form>

我要寻找一种方法,使这使得提交表单的时候,下面的数据结构被传递在$ _ POST:

I am looking for a way to make it such that when the form is submitted, the following data structure gets passed in $_POST:

 [chapter] => Array
  (
    [0] => Array
        (
            [id] => corresponding chapter ID
            [name] => corresponding chapter name
            [password] => corresponding chapter password
        )

    [1] => Array
        (
            [id] => corresponding chapter ID
            [name] => corresponding chapter name
            [password] => corresponding chapter password
        )

)

我试过名='章[] [ID]'/名称='章[] [名]'/名称='章[] [密码]'的各种组合,但收效甚微。该阵列永远看起来像什么,我希望它看起来像。

I tried various combinations of name='chapter[][id]' / name='chapter[][name]' / name='chapter[][password]' with little success. The array data structure never looks like what I want it to look like.

任何想法?

推荐答案

以下似乎为我工作:

<input type='text' name='chapters[0][id]'>
<input type='text' name='chapters[0][name]'>
<input type='password' name='chapters[0][password]'>

<input type='text' name='chapters[1][id]'>
<input type='text' name='chapters[1][name]'>
<input type='password' name='chapters[1][password]'>

这篇关于我将如何创建HTML表单这个数组结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆