【问题标题】:I'm trying to create a simple form using ExtJS and send the value into database我正在尝试使用 ExtJS 创建一个简单的表单并将值发送到数据库
【发布时间】:2014-08-14 04:23:37
【问题描述】:

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

感谢进阶的人


使用 Extjs 5 的 PS 即时通讯

//我的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')";
}

?>

【问题讨论】:

  • 你做了什么调试?值是否正确发送到服务器?
  • 在我的萤火虫中没有错误..."POST localhost/grid/grid/data/testform.php 200 OK 3ms".. 但在 POST 中没有任何视图

标签: extjs extjs4.2 extjs5


【解决方案1】:

我猜你的请求正文是空的,不是吗?尝试将表单数据插入到您的 Ajax 请求的 params: 配置中。 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()

【讨论】:

  • 我照你说的做...看上面的代码我编辑它..仍然没有插入值到数据库中
  • 您的请求正文中有数据吗?顺便说一句,你能检查一下 isset($_POST['submit']) 返回什么吗?在您的 php 代码中放置一些回声,检查您的 php 请求的响应。我猜 isset($_POST['submit']) 返回 false ,所以你的 php 脚本不会进入 if 语句。尝试 if(isset($_POST['Test1']))... 或将提交属性添加到您的参数 json。
  • 您是否也检查了我建议的其他内容?
  • 是的..我删除 isset($_POST['submit']){} 然后我将所有的 $_POST 更改为 ..$Test1= isset($_POST['Test1']) ? $_POST['Test1'] : NULL;依此类推..并添加一个 echo $Test1 但并将其检查到 php 文件但注意输出并且仍然没有将表单的值插入到数据库中...感谢您帮助我...您能再次提供帮助吗谢谢
【解决方案2】:

感谢@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);



?>

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

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    • 2019-01-06
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 2012-02-04
    相关资源
    最近更新 更多