Extjs - 在 FormPanel 中动态生成字段

发布于 2024-09-02 12:26:49 字数 1895 浏览 4 评论 0原文

我有一个生成表单面板的脚本:

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.')
                }
            });
        }
    }]
});

然后,相同的脚本从我的服务器检索一个 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;
    }
});

最后,表单被添加到我的界面中的相应面板中:

panel.add(form);
panel.doLayout();

我遇到的问题是:当我通过单击按钮提交表单时,发送到我的服务器的 http 请求不会包含添加到表单的字段。换句话说,我不会将这些字段发布到服务器。

有人知道为什么以及我该如何解决这个问题吗?

I've got a script that generates a form panel:

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.')
                }
            });
        }
    }]
});

that same scripts then retrieves a json file from my server which defines how many input fields that form should contain. The script then adds those fields to the form:

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;
    }
});

Finally, the form is added to the appropriate panel in my interface:

panel.add(form);
panel.doLayout();

The problem I have is: when I submit the form by clicking on the button, the http request sent to my server does not contain the fields added to the form. In other words, I'm not posting those fields to the server.

Anyone knows why and how I could fix that?

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

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

发布评论

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

评论(2

两相知 2024-09-09 12:26:49

你的问题在这里:

id: 'form-exploit-zombie-'+zombie_ip,
formId: 'form-exploit-zombie-'+zombie_ip,

你所做的是将表单面板的 id 属性和表单(表单标签)的 id 属性设置为相同的值。这意味着您有两个具有相同 id 的元素,这是错误的。

只要删除这条线

formId: 'form-exploit-zombie-'+zombie_ip,

就可以了。

Your problem is here:

id: 'form-exploit-zombie-'+zombie_ip,
formId: 'form-exploit-zombie-'+zombie_ip,

what you are doing is that you are setting the id attribute of the form panel and the id attribute of the form (form tag) to the same value. Which means that you have two elements with the same id and that is wrong.

Just remove this line

formId: 'form-exploit-zombie-'+zombie_ip,

and you should be fine.

倾`听者〃 2024-09-09 12:26:49

您是否检查了 HTTP 请求参数中的表单值?

如果服务器端使用 PHP,那么通过传递任何字段名称,您会从响应中得到什么?例如,如果您的输入名称之一是“xyz”,您会得到什么

$_POST[ 'txt_xyz' ]

Did you check the HTTP Request parameter for the form values?

If you server side is in PHP, what do you get from response by passing any field name? For example, if one of your input name was "xyz" what do you get by

$_POST[ 'txt_xyz' ]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文