动态添加的表单元素无法发布

发布于 2024-12-01 21:42:01 字数 167 浏览 0 评论 0原文

我有一个表单,其中有一组被克隆的元素。该表单允许用户输入多辆车辆,并克隆多个属性(年份、品牌、型号等)。我已经成功克隆了这些元素,并且它们具有唯一的名称。但是,在发布表单后,只有动态创建的元素才会被发布,并且可以使用 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

止于盛夏 2024-12-08 21:42:01

我粗略地看了你的代码。我认为问题出在提交表格之后。元素是动态生成的。

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

豆芽 2024-12-08 21:42:01

我知道 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 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
    } );
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文