简体   繁体   English

动态添加的表单元素不会发布

[英]Dynamically Added Form Elements Won't Post

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. 但是,发布表单后,只有动态创建的元素才会发布,并且可以使用PHP进行访问。 If you need to look at my code, I can post it on here, it's just a little lengthy. 如果您需要查看我的代码,可以将其发布在这里,这有点冗长。 Thanks! 谢谢!

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): 我知道OP很旧,但是以防万一有人也遇到这个问题...将动态添加或修改的元素的值发布到PHP的一种方法是使用jQuery的serialize() (OP似乎正在使用无论如何):

$( "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
    } );
});

I had a rough look at your code. 我粗略地看过您的代码。 I think the problem is after submission of the form. 我认为问题在于提交表格后。 The Elements are dynamically generating properly. 元素正在动态地正确生成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM