简体   繁体   中英

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. 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):

$( "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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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