在Sencha Touch 2中提交表单

时间:2012-03-23 16:38:40

标签: extjs sencha-touch-2

我正在尝试使用我下载的SDK中提供的标准表单提交表单。

任何人都有关于它如何通过的任何信息?关于如何传递它的任何提示?

我正在尝试制作一个非常简单的提交表单来收集一些信息。

{                    title: 'Register',
                    iconCls: 'add',
                    xtype: 'formpanel',
                    url: 'contact.php',
                    layout: 'vbox',
                    scrollable: true,



                    items: [
                        {
                            xtype: 'fieldset',
                            title: 'Opt In',
                            instructions: 'Want more info on Monster Energy? Opt-in to receive updates. ',

                            items: [
                                {
                                    xtype: 'textfield',
                                    label: 'First Name',
                                    name: 'fname',
                                },
                                {
                                    xtype: 'textfield',
                                    label: 'Last Name',
                                    name: 'lname',
                                },
                                {
                                    xtype: 'emailfield',
                                    label: 'Email',
                                    name: 'email',
                                },
                                {
                                    xtype: 'numberfield',
                                    label: 'Phone',
                                    name: 'phone',
                                }
                            ]
                        },
                        {
                            xtype: 'button',
                            text: 'Send',
                            ui: 'confirm',
                            handler: function() {
                                this.up('formpanel').submit();
                            }
                        }
                    ]
                }

contact.php

<?phpinclude_once "config.php";
mysql_connect($dbhost, $dbuser, $dbpasswd);
mysql_select_db($dbname) or die ("Cannot select db" . mysql_error());
session_start();


//***** Get today's date
$today = date("Y-m-d H:i:s");
$date = date("Y-m-d");


$firstName = addslashes($_POST['fname']);
$lastName = addslashes($_POST['lname']);
$email = $_POST['email'];
$phone = $_POST['phone'];


$sql = "INSERT INTO customer_31
            (mb_firstName, 
            mb_lastName,
            mb_phone,
            mb_email,
            mb_date_entered) 
            VALUES 
            ('$firstName', 
            '$lastName', 
            '$phone',
            '$email')";




header("location:index.php");
exit();

?>

2 个答案:

答案 0 :(得分:0)

您需要从php

中的INSERT语句中删除mb_date_entered

答案 1 :(得分:0)

好的,虽然我还没有使用.up和表单提交我之前做了类似的事情,并通过首先在父项上使用getValues(),进行一些验证然后将其解雇到PHP。这里有一些代码希望它有所帮助:

handler: function(btn){
            var vals = btn.parent.parent.getValues();
            vals.time = new Date();

           //basic email validation
            var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
            var result=re.test(vals.email);
            if (result === true){
                Ext.Ajax.request({
                url: btn.parent.parent.getUrl(),
                params: {   
                        data:Ext.JSON.encode(vals),
                        encoded: vals.toString(),
                        vals: 'other='+JSON.stringify(vals)
                        },
                success: function(res, vals){
                        console.log(res);
                        console.log(JSON.stringify(vals));
                        Ext.Viewport.getMasked().hide();
                        Ext.Msg.alert('Thank you', 'Message received successfully.', Ext.emptyFn);
                        Ext.getCmp('contactForm').reset();
                        },

                failure: function(res){
                        console.log('form not submitted', res);
                        Ext.Viewport.getMasked().hide();
                        Ext.getCmp('contactForm').reset();
                        Ext.Msg.alert('Sorry something went wrong', 'Please try that again', Ext.emptyFn);
                        }
                });
            }

            if (result === false){
                Ext.Viewport.getMasked().hide();
                Ext.Msg.alert('Invalid Email', 'Please try again', Ext.emptyFn);
                Ext.getCmp('contactForm').reset();

            }
        }

PHP

<?php
        $errorMessage = "";

            $db = mysql_connect("YOURDB","USER","PASS");
            if(!$db) die("Error connecting to MySQL database.");
            mysql_select_db('formtest' ,$db);

            $json = $_POST['data'];
            $json = utf8_encode($json);

            $insert = "INSERT INTO formdata VALUES ('".$json."')";

            var_dump($_GET);

            if(mysql_query($insert))
            {
                echo('values inserted successfully');
                header("Location: thankyou.html");

            }
            else
            {
                echo('failure' . mysql_error());
            }

            exit();
?>