2011-05-23 147 views
0

我有這段代碼。如果我點擊按鈕我的表單參數插入數據庫。我怎麼能做到這一點?我應該寫什麼? 如果我點擊重置窗體,我的窗戶關閉。請幫忙!謝謝!extJS如何通過按鈕POST參數?

var AddQuestion = new Ext.Button({ 
     method  : 'POST', 
     url   : '/questions/create', 
     tooltip  : 'Add Question', 
     icon  : '/images/icons/silk/add.png', 
     iconCls  : 'add', 
     style  : 'margin-right: 60px;float:right;', 
     handler  : function() { 
        new Ext.Window({ 
        title  : 'Add Question', 
        width  : 700, 
        height  : 800, 
        bodyStyle : 'padding: 10px',      
        layout  : 'form', 
        modal  : true, 
        closable : true, 
        resizable : false,        
        draggable : false, 
        autowidth : true, 
        items  :[ 
            { 
             fieldLabel  : 'Question', 
             name   : 'question[text]', 
             xtype   : 'htmleditor', 
             enableFont  : false, 
             enableFormat : false, 
             enableFontSize : false, 
             enableLists  : false, 
             enableAlignments: false, 
             enableFont  : false, 
             enableColors : false, 
             height   : 160, 
             width   : 560    
            }, 
            { 
             name   :'form_type', 
             fieldLabel  :'Form Type', 
             xtype   :'combo', 
             triggerAction :'all', 
             mode   :'local', 
             editable  : false, 
             allowBlank  : false, 
             emptyText  :'You should Choose any...', 
             store   :new Ext.data.SimpleStore({ 
             fields   :['mode', 'name'], 
             data   :[ 
                 ['1', 'TextArea Question'], 
                 ['2', 'Scale Question'], 
                 ['3', 'TextArea + Scale Question'] 
             ] 
             }), 
             displayField :'name', 
             valueField  :'mode', 
             hiddenName  :'form_type' 
             }, 
             { 
              xtype    : 'itemselector', 
              name    : 'selected_respondents',      
              imagePath   : '../ux/images/', 
              bodyStyle    : 'background:#DFE8F6', 
                multiselects: [{ 
                 legend  : 'All Respondents', 
                 width   : 270, 
                 height  : 350, 
                 store   : st, 
                 displayField : 'email', 
                 valueField : 'id', 
                 hiddenName : 'email'          
                },{ 
                 legend  : 'Selected Respondents',    
                 width   : 270, 
                 height  : 350, 
                 store   : st2, 
                 displayField : 'email', 
                 valueField : 'id', 
                 hiddenName : 'email' 
                }] 
              }, 
              { 
              fieldLabel  :'To do', 
              xtype   : 'button', 
              text   : 'Refresh respondents ↑', 
              height   : 30,    
              icon   : '/images/icons/silk/arrow_refresh_small.png', 
              width   : 180, 
              handler: function(){ 
               if((who_is_admin == '1') || (who_is_admin == '0')){ 
                if (st2.getCount() == 0){ 
                 st.reload(); 
                }else 
                { 
                 Ext.Msg.show({ 
                  title   : 'Message for You', 
                  msg   : "You should left <i>'Selected Respondents'</i> field empty to <b>refresh</b> some changes!", 
                  modal   : true, 
                  Height  : 200, 
                  closable  : true, 
                  resizable  : false,        
                  draggable  : false,   
                  Width   : 300, 
                  buttons  : Ext.Msg.OK 
                 });         
                } 
             } 
           } 

         }, 
         { 
         xtype  : 'checkbox', 
         boxLabel : 'Make Question Active', 
         inputValue : '1', 
         name  : 'is_active', 
         hiddenName : 'is_active', 
         checked  : true 
         },                     
        ], 
        buttons: [{ 
        text: 'Reset Form', 
        handler: function(){ 
         } 
        },{ 
        text: 'Submit Form', 
        handler: function(){ 

         } 
        } 
      }] // button end 
        }).show(); //show window 
       } 

    });  
+0

你想提交表單異步(AJAX)? – Dve 2011-05-23 08:07:19

+0

yeye,我想如果我點擊我的這個窗口關閉和參數發送。 – 2011-05-23 08:09:34

回答

1

您可以通過在用戶點擊按鈕後立即發送AJAX請求來做到這一點。 比如,對於你的情況處理程序「提交表單」按鈕應該像

Ext.Ajax.request({ 
    url:'assertion.htm', // url of page where you want to send it 
    method: 'POST',   
    params: { 
      selectedSource:source.getValue() //Right hand side whatever value you want to send 
    }, 
    scope:this 
});