统一包含许多表单字段的克隆框的数组

时间:2013-09-08 13:48:06

标签: php jquery

我有这个表格http://jsfiddle.net/U7Wp2/,我发布到这个PHP脚本

<?php
$all = $_POST;

echo '<pre>';
print_r($all);
echo '<pre>';

?>

我得到以下数组

<pre>Array
(
    [one] => 1
    [two] => 2
    [three] => 3
    [four] => 4
    [cr_one] => Array
        (
            [0] => aa
            [1] => ee
        )

    [cr_two] => Array
        (
            [0] => bb
            [1] => ff
        )

    [cr_three] => Array
        (
            [0] => cc
            [1] => gg
        )

    [cr_four] => Array
        (
            [0] => dd
            [1] => hh
        )

    [six] => 6
    [seven] => 7
    [eight] => 8
    [kr_one] => Array
        (
            [0] => tt
            [1] => pp
            [2] => er
        )

    [kr_two] => Array
        (
            [0] => rr
            [1] => oo
            [2] => en
        )

    [kr_three] => Array
        (
            [0] => uu
            [1] => ll
            [2] => et
        )

    [kr_four] => Array
        (
            [0] => yy
            [1] => qq
            [2] => ey
        )

    [ten] => 10
    [eleven] => 11
    [twelve] => 12
)
<pre>

要生成数组,我使用five crud按钮克隆2,使用nine_crud按钮克隆3。每个克隆形式有四个字段。生成的数组的问题是,每个克隆的表单字段被严重拆分并且不会一起出现(字段1到字段4)作为数组。例如在此数组中

[kr_one] => Array
    (
        [0] => tt
        [1] => pp
        [2] => er
    )

[kr_two] => Array
    (
        [0] => rr
        [1] => oo
        [2] => en
    )

[kr_three] => Array
    (
        [0] => uu
        [1] => ll
        [2] => et
    )

[kr_four] => Array
    (
        [0] => yy
        [1] => qq
        [2] => ey
    )

在这个数组中,我有三个不同的克隆项,但它们不会显示为单个数组。我可以为单个克隆框中的字段显示为统一数组吗?

1 个答案:

答案 0 :(得分:1)

如果只需要一个数组,则必须为每个克隆框添加相同的name属性。对于四个方框,这是name='kr[]'

然后在PHP中,如果你克隆了3次,你将得到12个值的数组。像这样:

[kr] => Array
(
    [0] => tt
    [1] => rr
    [2] => uu
    ....
    ....
    [11] => ey
)