Dynamically Added Form Elements Won't Post

2019-07-30 15:13发布

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!

2条回答
Ridiculous、
2楼-- · 2019-07-30 15:43

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
    } );
});
查看更多
萌系小妹纸
3楼-- · 2019-07-30 15:44

I had a rough look at your code. I think the problem is after submission of the form. The Elements are dynamically generating properly.

查看更多
登录 后发表回答