Posting form data and ajax updates

  • Hi Guys. I'm new to extjs so I will probably be asking a lot of questions, hope I don't become a pain.

    I have the following as a form panel, which is a simple keyword search


    var keyword_search = new Ext.FormPanel({

    renderTo: 'contentDiv',
    labelWidth:160,
    frame:false,
    autoWidth:true,
    bodyStyle:'padding:20px 20px 20px 20px',
    defaults: {width: 400},
    defaultType:'textfield',
    method:'POST',
    enctype : 'multipart/form-data',

    items: [{
    fieldLabel: 'Keyword',
    name: 'keyword',
    value: ''
    },
    new Ext.form.Hidden({
    name: 'search',
    value: 'keyword'
    }),
    ],

    buttons: [{
    text: 'Save',
    handler:function(){
    profile.getForm().submit({
    method:'POST',
    enctype : 'multipart/form-data',
    waitTitle:'Connecting',
    waitMsg:'Searching catalogue...',
    url:'content.php?action=course_catalogue',
    success:function(){
    Ext.Msg.alert('Ok', 'Profile update successful!');
    },
    failure:function(form, action){
    if(action.failureType == 'server'){
    obj = Ext.util.JSON.decode(action.response.responseText) ;
    Ext.Msg.alert('Profile update failed!', obj.errors.reason);
    }else{
    Ext.Msg.alert('Warning!', 'Authentication server is unreachable !');
    }
    //simple.getForm().reset();
    }
    });
    }
    }]
    });


    How would I go about changing this so that instead of it returning the message alert on success, it still posts the form variables to the url specified in the save button, but then returns the resulting output to the contentDiv div using the extjs ajax updater functionality.

    Thanks in advance


  • JSON is already decoded in action.result.


  • Unfortunately not, but thanks for the link, I will use it in future should I get stuck on something else.


  • Try this:

    success:function(form, action){
    // Ext.Msg.alert('Ok', 'Successful!');
    Ext.fly('server-result').update(action.result.msg);

    /*
    bascially (I'm guessing) what I need to do is get the return data
    from form_submit_test.php here and then update contentDiv
    to display it ?
    */
    },

    And server:

    if ($return){
    echo '{success:true,msg:"A message delivered from server"}';
    }else {
    echo '{success: false,
    errors: {
    reason: "An error occured with the form submission"
    }}';

    }

    Add


  • Try this:

    success:function(form, action){
    // Ext.Msg.alert('Ok', 'Successful!');
    Ext.fly('server-result').update(action.result.msg);

    /*
    bascially (I'm guessing) what I need to do is get the return data
    from form_submit_test.php here and then update contentDiv
    to display it ?
    */
    },

    And server:

    if ($return){
    echo '{success:true,msg:"A message delivered from server"}';
    }else {
    echo '{success: false,
    errors: {
    reason: "An error occured with the form submission"
    }}';

    }



    Add


  • Sorry I didn't see the form, action parameters for the success function.
    Added them, now I don't get an error, but the div does not update. I tested the update function by replacing action.response.msg with a simple string, and that works, so its just getting the data to return from the post url. Will keep trying my side, let me know if you think of anything.


  • If you prepare a showcase that is a complete html with embedded javascript that shows your problem, I can copy this html file to my filesystem and run and debug it locally. It can also be several files but it must be runnable here.

    This has always been the fastest way to help as I can modify your code, see the results immediately and post the solution back very fast.


  • haha, thats funny, i'm busy doing that right now as a way to show you what I want to do.:D

    Will post shortly... thanks for the assistance thus far


  • OK, you're welcome.

    To your original question: Could you please rephrase what is your desired behavior?

    To get fastest response in the case you post some code, post it in the form that can be copied somewhere to the Ext tree and run locally.


  • Does any of Form examples at http://examples.extjs.eu/ help?


  • jsakalos, I have attached the simple form post that I am using. The files are php, hope that is ok? I've also left out the 'adapter' and 'resources' folders from the extjs framework as it made my zip file to large.

    You'll see I have added notes in the scripts as to where I am lost. Basically I need to be able to return data on the form success function to then display in the main div ('contentDiv').

    Let me know if anything doesn't make sense.


  • Ok, thanks. I'm new to this, so you will have to tell me what you mean by post it in the form that can be copied somewhere to the Ext tree and run locally.


  • Ok I have it, thanks for pointing me in the right direction.

    Needed to code the success function like the error function


    success:function(form, action){
    obj = Ext.util.JSON.decode(action.response.responseText) ;
    Ext.fly('server-result').update(obj.msg);
    },


    Works brilliantly, thanks mate.:D


  • action is one of the arguments of success function. Have you added form and action arguments?


  • Thanks, will try it out. :)

    Do you mind if I post other questions regarding other stuff in this thread, or should I start a new one...just so much to learn.







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Posting form data and ajax updates , Please add it free.