2014-10-27 118 views
1

我搜索了小時和小時的解決方案,但找不到一個。我想提交一些php api函數。它看起來像這樣:Extjs表單提交

/*global Ext:false */ 

Ext.onReady(function() 
{ 

var i = 0; 
var form = Ext.create('Ext.form.Panel', { 

     title: 'base_entity_id', 
    bodyPadding: 5, 
    width: 350, 

    defaultType: 'textfield', 
    items: [{ 
     fieldLabel: 'base_entity_id', 
     name: 'first', 
     allowBlank: false 
    }], 
    buttons: [{ 
     text: 'Reset', 
     handler: function() { 
      this.up('form').getForm().reset(); 
     } 
    }, { 
     text: 'Submit', 
     formBind: true, 
     //only enabled once the form is valid 
     disabled: true, 
     handler: function() { 
      var form = this.up('form').getForm(); 
      } 
    }], 

    }) 

var tabs = Ext.create('Ext.tab.Panel', 
{ 
    renderTo: 'tabs', 
    id: 'tabs', 
    itemId: 'tabs', 
    fullscreen: true, 
    renderTo: document.body, 

    items: 
    [ 
     { 
      title: 'Home', 
      margin: 40, 
      items: [form], 

     }, 
     { 
     title: 'Results', 
     itemId: 'Results', 
     listeners: 
      { 
       activate: function (tab) 
        { 
         if(i == 0) 
          { 
            var panel = Ext.create('Ext.tab.Panel', 
            { 
             id: 'tabs2', 
             width: window, 
             height: window, 
             renderTo: document.body, 
            items: 
             [ 
              { 
               title: '1', 
               itemId: '1', 
               closable: true, 
               html: '10329u9iwsfoiahfahfosaofhasohflhsalkfhoihoi3riwoifhoiashfkhasofhosahfsahfahsfosafoisaiohfaoishfoihsaoifasoifsaifhsaoifasoihfoiahsfoihasfoihasoifoisfoihsafoihasfoiasoihasfoihaoifhaoihfoiahfoiaoaffoafoiafsaoafohaoh' 
              }, 
              { 
               title: '2', 
               itemId: '2', 
               closable: true, 
              } 
             ] 
                  }) 
              tab.add(panel); 
              tab.doLayout(); 
              i = 1; 
            } 
          } 
        } 
    }] 

}) 

});

但是,當我提交我沒有得到任何迴應,有人可以幫助我嗎?我不知道下一步是什麼?

+0

請發表您的代碼,整個表單,而不僅僅是提交按鈕。 – 2014-10-27 15:24:44

回答

0

好,你沒有爲你的表單設置URL,並且提交按鈕沒有提交方法,所以我不確定這應該如何工作。

您需要將url配置添加到您的形式:

Ext.create('Ext.form.Panel', { 
    title: 'base_entity_id', 
    method: 'POST', 
    url: 'myBackEnd.php' // Or whatever destination you are using for your backend. 
... 
}); 

而且,我看到你正在使用formbind: true,後來檢查,如果形式是有效的,一個動作將導致其他不必要的,所以選擇一,沒有必要兩個!

添加這是你的按鈕處理程序:

form.submit({ 
    params: { 
     id: form.getForm().getValues().first 
    }, 
    success: function(form, action) { 
     Ext.Msg.alert('Success', 'Your form was submitted successfully'); 
    }, 
    failure: function(form, action) { 
     Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response'); 
    } 
}); 

那麼你應該檢查$_POST['id']

有關表格的方法和配置的詳細信息,請查看此文檔:http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.form.Basic

+0

這對我有效!謝謝。唯一的問題是,我如何給我的POST變種命名?那麼我怎樣才能將輸入值作爲$ _POST ['id']來發布呢? – user3464409 2014-10-27 16:26:44

+0

你可以在你的提交方法中添加'params',真的,檢查文檔:http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.form.Basic-method-submit。這裏都有描述。我已將'params'配置添加到我的帖子中,以便您可以獲得一個示例。對於快速反應,Ty爲 – 2014-10-27 16:28:43

+0

。我覺得我沒有把自己弄清楚。 de form的值必須在$ _POST ['id']變量中 – user3464409 2014-10-27 16:42:19

1

我有分機JS/PHP做了一個簡單的應用程序和下面的代碼爲我工作:

myFormPanel.getForm().submit({ 
    clientValidation: true, 
    url: 'updateConsignment.php', 
    params: { 
     id: myFormPanel.getForm().getValues().first 
    }, 
    success: function(form, action) { 
     Ext.Msg.alert('Success', action.result.msg); 
    }, 
    failure: function(form, action) { 
     switch (action.failureType) { 
      case Ext.form.Action.CLIENT_INVALID: 
       Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values'); 
       break; 
      case Ext.form.Action.CONNECT_FAILURE: 
       Ext.Msg.alert('Failure', 'Ajax communication failed'); 
       break; 
      case Ext.form.Action.SERVER_INVALID: 
       Ext.Msg.alert('Failure', action.result.msg); 
     } 
    } 
}); 

來源: http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.form.BasicForm-method-submit

+0

問題是,當我這樣做時,我的提交按鈕不會執行任何操作.... – user3464409 2014-10-27 15:51:49

+0

您是否嘗試設置斷點或控制檯日誌? – dpalmero 2014-10-27 16:09:03