Results 1 to 5 of 5

Thread: trouble parsing a php result from a FormPanel

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    4
    Vote Rating
    0
      0  

    Question trouble parsing a php result from a FormPanel

    I've spent several hours at this, and if someone could point out my probably obvious error, much appreciated.

    The following code produces a valid JSON response, according to Firebug, but the failure: alert() fires, and none of the objects, like 'response' or 'jsonObject' are created. I've studied the docs and countless examples, trying both submit and ajax methods, no luck. I successfully parse a similar jsonObject elsewhere on my site from a callback function on an HTML form; I really want to use the Ext FormPanel for this though.

    This is my submit() attempt:
    Code:
        var fp = new Ext.FormPanel({
            url: 'handlers/q_big06.php',
            renderTo:'queryForm_full',
            items: [
                basicGroup, // set of comboboxes
                durationGroup // sets of radio buttons
            ],
            buttons: [{
                text: 'Send query',
                formBind: true,
                handler: function()    {
                    fp.getForm().submit({
                      success: function(a, b) {
                        var response = b.responseText;
                        // alert(response);
                        var jsonObject = eval('(' + response + ')');
                        // alert(jsonObject);
                        var cost = jsonObject.cost;
                        var length = jsonObject.length;
                        var j_format = new OpenLayers.Format.GeoJSON();
                        var vectorFeature = j_format.read(jsonObject.geom);
                        if (vectorFeature) {
                        // ... add it to the vectorLayer and print attribute values
                          vectorLayer.addFeatures(vectorFeature);
                          // alert('<b>Cost: </b>'+cost+'<br/><b>Length: </b>'+length+'<br/>(more or less)');
                        } else {
                          alert("Didn't get back GeoJSON it seems");
                        } //end if
                      }, // end success
                      failure: alert('failed'),
                  }); // end submit
                } // end handler
            },{
                text: 'Reset',
                handler: function(){
                    fp.getForm().reset();
                }
            }]
        });

  2. #2
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Huntsville
    Posts
    252
    Vote Rating
    -5
      0  

    Default

    Shouldn't that be failure: function() {
    alert('failed')
    }

    as it is, you are calling alert and assigning the return value to failure?

  3. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    4
    Vote Rating
    0
      0  

    Default made that change, no difference

    thanks for noting that -- made no difference though

    kg

  4. #4
    Sencha Premium Member
    Join Date
    May 2012
    Posts
    11
    Vote Rating
    0
      0  

    Default

    I am having a similar (but opposite) issue with the form panel.

    the form POSTs the information and runs login.php, but no matter what the login.php echos, the form follows the "success" code. How can I trigger the "failure" code?

    the SENCHA JS:______>

    Code:
    Ext.define('MyApp.view.LoginPanel', {
        extend: 'Ext.form.Panel',
    
        height: 400,
        width: 400,
        autoScroll: true,
        activeItem: 0,
        layout: {
            align: 'stretch',
            type: 'vbox'
        },
        bodyPadding: 10,
        title: 'LoginForm',
    
        initComponent: function() {
            var me = this;
    
            Ext.applyIf(me, {
                items: [
                    {
                        xtype: 'fieldset',
                        activeItem: 0,
                        title: 'Login',
                        flex: 0,
                        items: [
                            {
                                xtype: 'textfield',
                                name: 'username',
                                fieldLabel: 'Username',
                                allowBlank: false
                            },
                            {
                                xtype: 'textfield',
                                width: 255,
                                maintainFlex: false,
                                name: 'password',
                                fieldLabel: 'Password',
                                allowBlank: false
                            }
                        ]
                    },
                    {
                        xtype: 'gridpanel',
                        id: 'userInfo',
                        title: 'User Info',
                        store: 'UserStore',
                        columnLines: false,
                        flex: 1,
                        viewConfig: {
                            autoRender: true,
                            autoShow: true
                        },
                        columns: [
                            {
                                xtype: 'gridcolumn',
                                dataIndex: 'Username',
                                text: 'Username'
                            },
                            {
                                xtype: 'gridcolumn',
                                dataIndex: 'userID',
                                text: 'UserID'
                            }
                        ]
                    }
                ],
                dockedItems: [
                    {
                        xtype: 'toolbar',
                        height: 27,
                        width: 517,
                        dock: 'bottom',
                        layout: {
                            pack: 'end',
                            type: 'hbox'
                        },
                        items: [
                            {
                                xtype: 'button',
                                text: 'Login',
                                listeners: {
                                    click: {
                                        fn: me.onButtonClick,
                                        scope: me
                                    }
                                }
                            }
                        ]
                    }
                ]
            });
    
            me.callParent(arguments);
        },
    
        onButtonClick: function(button, e, options) {
            if (this.getForm().isValid()) {
                this.getForm().submit({
                    method: 'POST',
                    waitTitle: 'Connecting',
                    waitMsg: 'Sending data...',
                    url: 'login.php',
                    success: function(form, action) {
                        Ext.MessageBox.show({
                            title: '',
                            msg: 'Loading..',
                            progressText: 'Searching..',
                            width:300,
                            progress:true,
                            closable:false
                        });
                        window.location.reload();
                        Ext.MessageBox.show({
                            title:'Login Successful'
                        });
                    },
                    failure: function(form, action) {
                        Ext.Msg.alert('Login Failed!');
                    }
                });
            }
        }
    the LOGIN.PHP_____>

    *sensitive working database info has been replaced with stubs*

    Code:
    <html>
    <?php
        
        //attempt to connect to the server
        if (!($con = mysql_connect("testing.com","adminUser","adminPass")))
        {
              die('Could not connect: ' . mysql_error());
        }
        //select the correct database
        mysql_select_db("myDatabase", $con);
        
        //query the database
        $result = mysql_query("SELECT * FROM Users WHERE userUserName='$_POST[username]' AND userPassword='$_POST[password]'", $con);
        
        //if user and password combo doesn't exist
        if(mysql_num_rows($result)==0)
        {
          
            $response = array('success' => FALSE);
            echo json_encode($response);
        }
        
        else 
        {
            //create arrays to organize results
            $response = array();
            $posts = array();
            //for each result in the results table...
            while($row = mysql_fetch_array($result))
            {
                $password = $row['userPassword'];
                $username = $row['userUserName'];
                $userID = $row['userID'];
                
                //place the data into the associative array
                $posts[] = array('username' => $username, 'password' => $password, 'ID' => $userID);
            }
            
            //put the associative arrays into their parent object 'users'
            $response['users'] = $posts;
            
            //write results to .json file
            $fp = fopen('results.json', 'w');
            fwrite($fp, json_encode($response));
            fclose($fp);
            
            $response = array('success' => TRUE);
            echo json_encode($response);
            
        }
        
        
    ?>
    </html>

  5. #5
    Sencha User
    Join Date
    Sep 2009
    Posts
    6
    Vote Rating
    0
      0  

    Default

    Isnt failure for form load is triggerred if there are comms problem? like httcode 404, 500, no connection etc ...?

    Usually - if I need to handle error result, i set some error var in response and handle it within success: listener in form ajax load.

    if you need to handle it via failure listener - set your response http code to say 403 forbidden, and do your magic

    makes sense?

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
  •