动态添加表单元素不会发布 [英] Dynamically Added Form Elements Won't Post

查看:151
本文介绍了动态添加表单元素不会发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,其中有一组克隆的元素。该表格允许用户输入多个车辆,并克隆多个属性(年份,品牌,型号等)。我成功地克隆了这些元素,并且它们具有独特的名称。但是,在发布表单之后,只有 元素才会发布,并且可以通过PHP访问。如果您需要查看我的代码,我可以将其发布到此处,这只是一小段时间。谢谢!

I have a form in which there are sets of elements that are cloned. The form allows a user to input multiple vehicles, with multiple attributes being cloned (year, make, model, etc). I have successfully cloned the elements and they have unique names. However, after the form is posted, only the elements that were not dynamically created get posted and are there by accessible using PHP. If you need to look at my code, I can post it on here, it's just a little lengthy. Thanks!

推荐答案

我知道OP是相当老,但以防万一有人遇到这个问题......向PHP发布动态添加或修改的元素值的方式是使用jQuery的 serialize()(OP似乎正在使用它):

I know the OP is rather old, but just in case someone is encountering this problem as well... a way to post dynamically added or modified elements' values to PHP is to use jQuery's serialize() (which the OP seems to be using anyway):

$( "form" ).submit( function ( event ) {
    event.preventDefault();
    var url = $( this ).attr( "action" ),
        data = $( this ).serialize();
    $.post( url, data ).done( function() {
        // Redirect to a "sent" page or something
    } )
    .fail( function() {
        //etc etc
    } );
});

这篇关于动态添加表单元素不会发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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