dsl36367 2017-10-11 14:32
浏览 54

自动添加或删除表单中的行,使用PHP进行处理

I'm using the script below to automatically add new lines in a form, but I do not see how to retrieve the values ​​of each field under PHP with $_POST. If someone has already had this problem with a table in a form, thank you for helping me! what procedure to retrieve in test5.php the values ​​of the fields. I do not know how to get an array in a $_POST

thank you in advance

Here is my script

<html>

<head>
</head>

<body>
    <form action="test5.php" method="post">
        <div id="address">
            <div id="1" name="address[]">
                <input id="mail" type="text" />
                <input id="type" type="text" />
                <input id="comment" type="text" />
                <a href="#" class="removeclass" style="display:none;">&times;</a>
            </div>
        </div>

        <input id="add_address" type="button" value="Ajouter" />
        <input type="submit" value="Create PDF" />
    </form>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
        $('#add_address').click(function(event) {
            var lastDiv = $('#address > div').last();
            var id = parseInt(lastDiv.attr("id")) + 1;
            (lastDiv.clone(true).attr("id", id)).insertAfter(lastDiv).find(".removeclass").show();
            return false;
        });

        $('body').on('click', '.removeclass', function(event) {
            $(this).parent().remove();
            return false;
        })
    </script>
</body>

</html>
  • 写回答

2条回答 默认 最新

  • douqilin4296 2017-10-11 14:45
    关注

    1.) Remove the name-attribute from the div-element

    2.) Build your input-elements like:

    <div id="..">
    <input type="..." name="address[1][mail]" />
    <input type="..." name="address[1][type]" />
    <input type="..." name="address[1][comment]" />
    </div>
    <div id="..">
    <input type="..." name="address[2][mail]" />
    <input type="..." name="address[2][type]" />
    <input type="..." name="address[2][comment]" />
    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看