0

我正在尝试使用创建一个简单的表单ExtJS并将值发送到数据库中,但它不会将我输入的值插入到我的表单中。我不知道为什么它不将数据输入数据库。我不知道我的代码有什么问题......任何人都可以帮助我实现我想要做的事情。

感谢高级家伙


PS即时使用Extjs 5

//我的Extjs表格

 Ext.define('Grid.view.main.Form', {
        extend: 'Ext.form.Panel',
        xtype:'form',
        title: 'User Form',
        id:'myformpanel',
        height: 120,
        width: '100%',
        autoScroll:true,
        defaults: {
            xtype: 'textfield',
            labelAlign: 'top',
            padding: 10
        },
        layout: {
            type: 'hbox'
        },

        items: [{

                fieldLabel: 'TEST1',
                name: 'Test1'
            },{
                fieldLabel: 'TEST2',
                name: 'Test2'
            },{
                fieldLabel: 'TEST3',
                name: 'Test3'
            },{
                fieldLabel: 'TEST4',
                name: 'Test4'
            },{
                fieldLabel: 'TEST5',
                name: 'Test5'
            },{
                fieldLabel: 'TEST6',
                name: 'Test6'
            },{
                fieldLabel: 'TEST7',
                name: 'Test7'
            },{
                fieldLabel: 'TEST8',
                name: 'Test8'
            },{
                fieldLabel: 'TEST9',
                name: 'Test9'
            },{
                fieldLabel: 'TEST10',
                name: 'Test10'
            },{
                fieldLabel: 'TEST11',
                name: 'Test11'
            },{
                fieldLabel: 'TEST12',
                name: 'Test12'
            },

        ],



         buttons: [{
            text: 'login',
            name:'submit',

        handler: function(){
            Ext.Ajax.request({
        url: 'data/testform.php',
        method: 'POST',
        params: Ext.getCmp('myformpanel').getForm().getFieldValues(),
success: function(response){       
    Ext.Msg.alert('success ' + response.status);
},
failure: function(response){
    Ext.Msg.alert('server-side failure with status code ' + response.status);
}
});
                }
          });
        }
    }]

//testform.php

<?php

require_once('database_connection.php');

if(isset($_POST['submit'])){

    $Test1=$_POST['Test1'];
        $Test2=$_POST['Test2'];
        $Test3=$_POST['Test3'];
        $Test4=$_POST['Test4'];
        $Test5=$_POST['Test5'];
        $Test6=$_POST['Test6'];
        $Test7=$_POST['Test7'];
        $Test8=$_POST['Test8'];
        $Test9=$_POST['Test9'];
        $Test10=$_POST['Tes10t'];
        $Test11=$_POST['Test11'];
        $Test12=$_POST['Test12'];

        $query="INSERT INTO testexcel (Test1,Test2,Test3,Test4,Test5,Test6,Test7,Test8,Test9,Test10,Test11,Test12) VALUES ('$Test1','$Test2','$Test3','$Test4','$Test5','$Test6','$Test7','$Test8','$Test9','$Test10','$Test11','$Test12')";
}

?>
4

2 回答 2

1

我猜你的请求正文是空的,不是吗?尝试将表单数据插入到params:Ajax 请求的配置中。http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.Ajax

Ext.Ajax.request({
    url: 'data/testform.php',
    method: 'POST',
    params: this.ownerCt.ownerCt.getForm().getFieldValues(),
    success: function(response){       
        Ext.Msg.alert('success ' + response.status);
    },
    failure: function(response){
        Ext.Msg.alert('server-side failure with status code ' + response.status);
    }
});

this.ownerCt.ownerCt.getForm()不是获取表单的最佳方式 - 尽管在您的示例中我找不到其他方式来访问它。如果你更喜欢,你可以给你的表格id和工作。Ext.getCmp(id)这看起来像这样params: Ext.getCmp('myformpanel123').getForm().getFieldValues()

于 2014-08-14T06:38:21.210 回答
0

感谢@Hown_先生帮助我...我弄清楚为什么没有将我的数据插入数据库的问题...因为我的数据库配置错误所以这是我的代码

//我的extjs表单面板

Ext.define('Grid.view.main.Form', {
    extend: 'Ext.form.Panel',
    xtype:'form',



    title: 'User Form',
    id:'myformpanel',
    height: 120,
    width: '100%',
    autoScroll:true,
    defaults: {
        xtype: 'textfield',
        labelAlign: 'top',
        padding: 10
    },
    layout: {
        type: 'hbox'
    },

    items: [
        {
            fieldLabel: 'TEST1',
            name: 'Test1'


        },{
            fieldLabel: 'TEST2',
            name: 'Test2'
                    },{
            fieldLabel: 'TEST3',
            name: 'Test3'
                   },{
            fieldLabel: 'TEST4',
            name: 'Test4'
                    },{
            fieldLabel: 'TEST5',
            name: 'Test5'
                    },{
            fieldLabel: 'TEST6',
            name: 'Test6'
                    },{
            fieldLabel: 'TEST7',
            name: 'Test7'
                    },{
            fieldLabel: 'TEST8',
            name: 'Test8'
                    },{
            fieldLabel: 'TEST9',
            name: 'Test9'
                    },{
            fieldLabel: 'TEST10',
            name: 'Test10'

        },{
            fieldLabel: 'TEST11',
            name: 'Test11'

        },{
            fieldLabel: 'TEST12',
            name: 'Test12'

        },

    ],

    buttons: [{


        text: 'login',
        name:'submit',

    handler: function()
    {



        Ext.Ajax.request({
            url: 'data/testform.php',
            method: 'POST',
            params: Ext.getCmp('myformpanel').getForm().getFieldValues(),
                success: function(response){       
                 Ext.Msg.alert('success ' + response.status);
    },
                failure: function(response){
                Ext.Msg.alert('server-side failure with status code ' + response.status);
    }
    });




    }]



});

//我的testform.php

<?php

require_once('database_connection.php');




    $Test1= isset($_POST['Test1']) ? $_POST['Test1'] : NULL;
    $Test2= isset($_POST['Test2']) ? $_POST['Test2'] : NULL;
    $Test3= isset($_POST['Test3']) ? $_POST['Test3'] : NULL;
    $Test4= isset($_POST['Test4']) ? $_POST['Test4'] : NULL;
    $Test5= isset($_POST['Test5']) ? $_POST['Test5'] : NULL;
    $Test6= isset($_POST['Test6']) ? $_POST['Test6'] : NULL;
    $Test7= isset($_POST['Test7']) ? $_POST['Test7'] : NULL;
    $Test8= isset($_POST['Test8']) ? $_POST['Test8'] : NULL;
    $Test9= isset($_POST['Test9']) ? $_POST['Test9'] : NULL;
    $Test10= isset($_POST['Test10']) ? $_POST['Test10'] : NULL;
    $Test11= isset($_POST['Test11']) ? $_POST['Test11'] : NULL;
    $Test12= isset($_POST['Test12']) ? $_POST['Test12'] : NULL;


        $query="INSERT INTO testexcel (Test1,Test2,Test3,Test4,Test5,Test6,Test7,Test8,Test9,Test10,Test11,Test12) VALUES ('$Test1','$Test2','$Test3','$Test4','$Test5','$Test6','$Test7','$Test8','$Test9','$Test10','$Test11','$Test12')";
        mysql_query($query,$con);



?>

希望这段代码能帮助像我这样的初学者......

谢谢

于 2014-08-15T03:55:29.137 回答