简体   繁体   English

字段会动态添加到表单中,但不会提交到服务器

[英]Fields are added dynamically to the form but not submitted to the server

I want to be able to add different fields to the form on the fly and then submit them to the server.我希望能够动态地向表单添加不同的字段,然后将它们提交到服务器。 This is how I do that:这就是我这样做的方式:

var frm = this.up('window').down('form');
for(var i = 0; i < 3; i++){
    var el = Ext.create('Ext.form.field.Text',{
                 xtype:'textfield',
                 name:'field_' + i
             });
    frm.items(add);
}
alert(frm.getForm().getFields().length); // alerts "0";

It is really interesting, because I even see three new fields in the form - they have their unique ids, names, etc. But for some insane reason frm.getForm().getFields().length gives me zero, even if I defer this by 2, 5 or infinity seconds.这真的很有趣,因为我什至在表单中看到了三个新字段——它们有它们唯一的 ID、名称等。但是出于某种疯狂的原因frm.getForm().getFields().length给了我零,即使我推迟这是 2、5 或无限秒。 What is going on???到底是怎么回事???

Try:尝试:

frm.add(el);

Instead of:代替:

frm.items(add);

There could be some protection on Server Side against that (in order to protect against XSS )服务器端可能会有一些保护措施(为了防止XSS

I have faced with same when worked with Drupal (Apache), but I'm sure it's generic practice for many frameworks/servers.我在使用 Drupal (Apache) 时也遇到过同样的情况,但我确信这是许多框架/服务器的通用做法。

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

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