1. #1
    Sencha User
    Join Date
    Jun 2009
    Posts
    46
    Vote Rating
    15
    Max_nl will become famous soon enough

      0  

    Default Form posts and error handling using ext.direct PHP

    Form posts and error handling using ext.direct PHP


    Hi,

    I am new to ext.js and am experimenting with form submits in combination with the Ext.Direct PHP stack.
    In another thread it is suggested to use the api property of the form for that.

    So I created a setup among the lines of:

    Code:
    Ext.Direct.addProvider(Ext.app.REMOTING_API);
    
    var form = new Ext.form.FormPanel({
      api: {
         submit: MyClass.submit
      },
    
    [...other form stuff...]
    
      buttons: [{
        text: 'Submit',
              handler:function(){ 
                   form.getForm().submit();
              }
    And on the server I created a simple class like:

    Code:
    class MyClass {
       /**
        * @remotable
        * @formHandler
        */
      function submit($fields, $files)
       {
        [ .... code that inserts the information from the $fields array to the database ....]
       }
    }
    While this seems to work, it is not clear to me what my submit( ) function should do in case an error occurs on the server, or if something is wrong with the data the user entered.

    If I simply throw a PHP exception, it results in a javascript error on the browser:

    Code:
    Error: result is undefined
    Source File: http://[ip]/ext/ext-all-debug.js
    Line: 35527
    So apparently that is not the way to go.
    Do I have to "return" something instead to indicate an error to the client?

  2. #2
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    481
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

  3. #3
    Sencha User
    Join Date
    Jun 2009
    Posts
    46
    Vote Rating
    15
    Max_nl will become famous soon enough

      0  

    Thumbs up


    Thanks for the tip.
    The following PHP code indeed causes a red border around the form field affected.

    PHP Code:
    return array(
                    
    "success" => false
                    
    "errors"  => array("name-of-form-field" => "message")
                 ); 
    And after adding this to the Javascript, it also displays the message.

    PHP Code:
    Ext.QuickTips.init(); 
    Ext.form.Field.prototype.msgTarget 'side'
    Is there also a standardized way to alert the client of global errors that are not specific to a single form field?
    E.g. when the form information could not be added to the database, because the database server is down.

    Or do I need to attach a custom callback to the "failure" property, and handle that myself?

  4. #4
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    481
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    Quote Originally Posted by Max_nl View Post
    Is there also a standardized way to alert the client of global errors that are not specific to a single form field?
    E.g. when the form information could not be added to the database, because the database server is down.

    Or do I need to attach a custom callback to the "failure" property, and handle that myself?
    It's a good question. I'm not sure. In Ext JS 3.0 there's a new Ext.Error class, you can try to use it. I'm going to look into it myself.

Thread Participants: 1