Results 1 to 6 of 6

Thread: How to get response JSON after form submitting?

  1. #1

    Default How to get response JSON after form submitting?

    I use simple way to submit my form and I want to get response JSON to provide user with some kind of notification or with the error message. I've tried to pass callback parameter to the submit function, but it doesn't works. Help please...

    P.S. I've also tried to set event handler on the actioncomplete event, but it doesn't works too. I'm frustrated. Here is my code:
    Code:
    Ext.QuickTips.init();
      Ext.form.Field.prototype.msgTarget = 'side';
      var field_w = 150;
      var label_w = 120;
      
      f = new Ext.form.Form({
        id: 'reg-form',
        labelWidth: label_w,
        url: '/ajax.php?module=users.registration'
      });
    
      f.add(
        new Ext.form.TextField({
          fieldLabel: 'Your LDAP core ID',
          name: 'reg_id',
          width: field_w,
          allowBlank: false
        }),
        new Ext.form.TextField({
          fieldLabel: 'Your LDAP password',
          inputType: 'password',
          name: 'reg_pass',
          width: field_w,
          allowBlank: false
        }),
        new Ext.form.ComboBox({
          fieldLabel: 'Your MBG',
          hiddenName: 'reg_mbg',
          allowBlank: false,
          store: new Ext.data.SimpleStore({
             fields: ['id_mbg', 'mbgName'],
             data: Ext.admin.mbgs
          }),
          emptyText:'Select an MBG...',
          valueField:'id_mbg',
          displayField:'mbgName',
          mode: 'local',
          width: field_w
        })
      ); 
      
      f.addButton({
        text: 'Submit',
        handler: function(){
          if (f.isValid()) {
            f.submit();
          }
          else {
            alert('Please fix the errors noted.');
          }
        }
      });
      f.addButton({
        text: 'Reset',
        handler: function(){
          f.reset();
        }
      });
      
      f.render('reg-form-container');
    
      f.on({
        actioncomplete: function(form, action){
          if(action.type == 'submit'){
            ...
          }
        }
      });

  2. #2
    Ext Premium Member
    Join Date
    Mar 2007
    Location
    Quebec, Canada
    Posts
    831

    Default

    hey Karantir,

    I'm no Ext.Form user, but I know this for sure:
    logically, your server-side needs to spit out an answer before you can catch it and analyse it.
    and your handler isn't the right place to do it because the submit answer would happen some time after the handler is called. There must be an Ext.Form event to catch the answer you receive from your server-side.

    if I take a quick glance on the Ext.Form documentation I see these events:

    Code:
     	actioncomplete : ( Form this, Action action )  	BasicForm
    Fires when an action is completed.
      	actionfailed : ( Form this, Action action ) 	BasicForm
    Fires when an action fails.
      	beforeaction : ( Form this, Action action ) 	BasicForm
    Fires before any action is performed. Return false to cancel the action.
    so here it goes:
    Code:
    yourForm.on("actioncomplete", function(form, action){/*alert a success message*/}, this, true);
    
    yourForm.on("actionfailed", function(form,action){/*alert an error message*/}, this, true);
    keep in mind that if you catch an error on your server-side and respond back, it will be considered as an "actioncomplete" event. you need to return an appropriate message error in those case.

    good luck!

  3. #3

    Default

    Thank you very much for suggestions, Bernard. I also add event listener on autocomplete event . But it seems this event is not fired at all in my case... Very strange. Moreover, I've tried to add 'success' and 'failure' parameters to MyForm.submit() and it works (anyway it's strange, why callback parameter didn't work earler). But despite that I've returned valid JSON, failure function called anytime... Dark magic?

  4. #4

    Default

    And I've just found that it's not only my problem http://extjs.com/forum/showthread.php?t=9650 ...

  5. #5

    Default

    It seems here is the solution http://extjs.com/learn/Manual:Forms:Result_Format
    All the same, i believe, it's not good to do some inexplicit actions based on secret standards... Maybe somehow to reflect this feature in documentation?

  6. #6
    Ext Premium Member
    Join Date
    Mar 2007
    Location
    Quebec, Canada
    Posts
    831

    Default

    damn... that has to be in the docs alright! please ask it in the "missing documentation" discussion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •