2012-03-23 140 views
3

我試圖用我下載的SDK中提供的標準表單提交表單。在Sencha Touch 2中提交表單

任何人都有關於它是如何通過的信息?有關如何通過它的任何提示?

我試圖做一個非常簡單的提交表單來收集一些信息。

{     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(); 

?> 
+0

不知道這是什麼原因...但contact.php缺少一些代碼'的mysql_query($的SQL);' – 2012-09-03 11:27:01

回答

0

您需要從您的INSERT語句mb_date_entered在php

+0

試了一下,沒有任何區別。 (還添加了$ today變量,所以它應該可以工作) – GaelenN 2012-03-28 16:31:46

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._-][email protected][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(); 
?>