Results 1 to 5 of 5

Thread: Form submit always returns failure

  1. #1
    Sencha User kitesurf's Avatar
    Join Date
    Jan 2012
    Location
    London, England
    Posts
    78
    Answers
    4

    Default Answered: Form submit always returns failure

    I can't seem to ever get a success return after submitting a form. The response back to Sencha is valid JSON with the success tag set to true, but no matter what I try the failure action is always taken.

    I would be very grateful if someone could point me in the right direction. I've googled like mad to try and work this out.

    Many thanks

    I'm running Sencha Touch 1.1.0

    JSON response:
    Code:
    [{"success":"true","data":{"returnCode":"0"}}]
    Form Submit:
    Code:
      submit: function(options) {
        console.log("controllers.SignOnController - signOn");
        var theForm = Ext.getCmp('signOnForm');
        theForm.submit({
          method: 'POST',
          waitMsg: {
            message: 'Processing'
          },
          scope: this,
          success: function(form, response) {
            console.log("controllers.SignOnController - successful logon");
            Ext.dispatch({
              controller: 'Accounts',
              action: 'index',
              historyUrl: 'Accounts/index'
            })
          },
          failure: function(form, response) {
            Ext.Msg.alert('Login Failed: ', response.errorMessage);
          }
        })
        console.log("Submitted form...");
      }
    Form:
    Code:
    Aries.views.SignOnForm = Ext.extend(Ext.form.FormPanel, {
      scroll: 'vertical',
      id: 'signOnForm',
      url: proxyPrefix + '/signon',
      items: [{
        //add a fieldset
        xtype: 'fieldset',
        title: 'Authentication',
        instructions: 'Please enter the your login details',
        //apply the common settings to all the child items of the fieldset
        defaults: {
          required: true, //required field
          labelAlign: 'left',
          labelWidth: '40%'
        },
        items: [{ //add a text field
          xtype: 'textfield',
          name : 'username',
          label: 'Username',
          value: 'justin',
          useClearIcon: true, //shows the clear icon in the field when user types
          autoCapitalize : false
        },{ //add a password field
          xtype: 'passwordfield',
          name : 'password',
          label: 'Password',
          value: 'justin',
          useClearIcon: true
        },
          {
            xtype: 'button',
            text: 'Sign On',
            ui: 'confirm',
            width: '40%',
            handler: function() {
              Ext.dispatch({
                controller: 'SignOn',
                action: 'submit',
                data: Aries.views.SignOnForm
              });
            },
            scope: this
          }
        ],
        listeners : {
          //listener if the form is submitted, successfully
          submit : function(form, result){
            console.log('success', Ext.toArray(arguments));
          },
          //listener if the form submission fails
          exception : function(form, result){
            console.log('failure', Ext.toArray(arguments));
          }
        }
      }],
        initComponent: function() {
        Aries.views.SignOnForm.superclass.initComponent.apply(this, arguments);
      }
    });

  2. So I tried an Ajax request instead of the default form submit and this seems to have solved the problem. I now get back a success. For anyone else struggling, I changed my form submit as follows:

    Code:
       submit: function(options) {
            console.log("controllers.SignOnController - signOn");
            var theForm = Ext.getCmp('signOnForm')
    
            Ext.Ajax.request({
                url: proxyPrefix+"/signon",
                method: 'POST',
                params: theForm.getValues(),
                scope: this,
                success: function(form, response) {
                    console.log("controllers.SignOnController - successful logon");
                    Ext.dispatch({
                        controller: 'Accounts',
                        action: 'index',
                        historyUrl: 'Accounts/index'
                    })
                },
                failure:function(form, response) {
                    Ext.Msg.alert('Login Failed: ', response.errorMessage);
                }
            })
            console.log("Attempted to submit form...");
    
        }

  3. #2
    Sencha User kitesurf's Avatar
    Join Date
    Jan 2012
    Location
    London, England
    Posts
    78
    Answers
    4

    Default

    So I tried an Ajax request instead of the default form submit and this seems to have solved the problem. I now get back a success. For anyone else struggling, I changed my form submit as follows:

    Code:
       submit: function(options) {
            console.log("controllers.SignOnController - signOn");
            var theForm = Ext.getCmp('signOnForm')
    
            Ext.Ajax.request({
                url: proxyPrefix+"/signon",
                method: 'POST',
                params: theForm.getValues(),
                scope: this,
                success: function(form, response) {
                    console.log("controllers.SignOnController - successful logon");
                    Ext.dispatch({
                        controller: 'Accounts',
                        action: 'index',
                        historyUrl: 'Accounts/index'
                    })
                },
                failure:function(form, response) {
                    Ext.Msg.alert('Login Failed: ', response.errorMessage);
                }
            })
            console.log("Attempted to submit form...");
    
        }

  4. #3

    Default

    Would be interesting to hear comments from developers or support team, because I have same problem with both form.load/submit methods.

  5. #4

    Default Form submit always returns failure

    I might be too late for this but I faced a similar issue while working with form submit.
    The reason in your case is I think the "success" parameter is looking for a boolean value.
    So I think it should be
    Code:
    {"success" : true/false}
    Thats what I did in my case and it worked for me perfectly fine.

    Check this link for details:

    http://atechiediary.blogspot.com/201...s-failure.html

  6. #5
    Sencha Premium Member aswinramakrish's Avatar
    Join Date
    Aug 2011
    Location
    Denver, CO
    Posts
    15

    Default Content Type to "text/html"

    I'm not sure if the solution proposed above is the right solution. It won't work if the form is submitting files.

    I had the same issue and I had to set the Content Type (on the server side) of my response to "text/html" for it to work.

    Hope this helps!

Tags for this Thread

Posting Permissions

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