Ben*_*min 5 javascript forms extjs dynamic formpanel
我有一个生成表单面板的脚本:
var form = new Ext.FormPanel({
id: 'form-exploit-zombie-' + zombie_ip,
formId: 'form-exploit-zombie-' + zombie_ip,
border: false,
labelWidth: 75,
formBind: true,
defaultType: 'textfield',
url: '/ui/modules/exploit/new',
autoHeight: true,
buttons: [{
text: 'Execute exploit',
handler: function () {
var form = Ext.getCmp('form-exploit-zombie-' + zombie_ip);
form.getForm().submit({
waitMsg: 'Running exploit ...',
success: function () {
Ext.beef.msg('Yeh!', 'Exploit sent to the zombie.')
},
failure: function () {
Ext.beef.msg('Ehhh!', 'An error occured while trying to send the exploit.')
}
});
}
}]
});
Run Code Online (Sandbox Code Playgroud)
同样的脚本,然后检索从我的服务器JSON文件定义输入多少个字段的形式应该包含的内容.然后,该脚本将这些字段添加到表单中:
Ext.each(inputs, function(input) {
var input_name;
var input_type = 'TextField';
var input_definition = new Array();
if(typeof input == 'string') {
input_name = input;
var field = new Ext.form.TextField({
id: 'form-zombie-'+zombie_ip+'-field-'+input_name,
fieldLabel: input_name,
name: 'txt_'+input_name,
width: 175,
allowBlank:false
});
form.add(field);
}
else if(typeof input == 'object') {
//input_name = array_key(input);
for(definition in input) {
if(typeof definition == 'string') {
}
}
} else {
return;
}
});
Run Code Online (Sandbox Code Playgroud)
最后,表单将添加到我的界面中的相应面板中:
panel.add(form);
panel.doLayout();
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是:当我通过单击按钮提交表单时,发送到我的服务器的http请求不包含添加到表单的字段.换句话说,我不会将这些字段发布到服务器.
任何人都知道为什么以及如何解决这个问题?
你的问题在这里:
id: 'form-exploit-zombie-'+zombie_ip,
formId: 'form-exploit-zombie-'+zombie_ip,
Run Code Online (Sandbox Code Playgroud)
你正在做的是你将表单面板的id属性和表单(表单标签)的id属性设置为相同的值.这意味着你有两个具有相同id的元素,这是错误的.
只需删除此行即可
formId: 'form-exploit-zombie-'+zombie_ip,
Run Code Online (Sandbox Code Playgroud)
你应该没事
| 归档时间: |
|
| 查看次数: |
8581 次 |
| 最近记录: |