Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Submit multiple forms using single AjaxRequest

  1. #1
    Sencha User
    Join Date
    Jun 2009
    Location
    Italy
    Posts
    1,395

    Question Submit multiple forms using single AjaxRequest

    Hi guys,
    I'm going to ask you something stupid because I think someone ask you one thousand times but...
    How to submit multiple forms using a single AjaxRequest?

    I tried the following code but i dosn't success.

    PHP Code:
        var dbParams Ext.encode(Ext.getCmp('INDB-form').getForm().getValues());
        var 
    adminParams Ext.encode(Ext.getCmp('INAD-form').getForm().getValues());
        var 
    netParams Ext.encode(Ext.getCmp('NET-form').getForm().getValues());
        
         
    Ext.Ajax.request({
            
    method'post',
            
    url'setup.php',
            
    params: [ 
                
    dbParams,
                
    adminParams,
                
    netParams
            
    ],
            
    success: function(responseopts) {
                if (
    response.responseText == 'undefined') {
                    
                    
                }
            }
        }); 
    Does someone has a quick trick to do it?
    Thanks a lot for your help!

  2. #2
    Sencha User
    Join Date
    Mar 2008
    Posts
    566

    Default

    I think getValues will just return an array of the values and not the keys. Try getFieldValues() instead. An maybe combine your three vars instead of listing them as properties(maybe you need to use apply, not sure). I have not tested this, just a suggestion.

    Code:
    params: [ 
                dbParams+adminParams+netParams
            ],

  3. #3
    Sencha User
    Join Date
    Jun 2009
    Location
    Italy
    Posts
    1,395

    Default

    Hi moegal and thanks for your reply but it doesn't work.
    I tried your suggestions but nothing.
    Sure i could write down the code in the following way:

    PHP Code:
        var Ext.getCmp('fieldA').getValue();
        var 
    Ext.getCmp('fieldB').getValue();
        var 
    Ext.getCmp('fieldC').getValue();
        
         
    Ext.Ajax.request({
            
    method'post',
            
    url'setup.php',
            
    params: [ 
                
    'a'a,
                
    'b'b,
                
    'c'c
            
    ],
            
    success: function(responseopts) {
                if (
    response.responseText == 'undefined') {
                    
                    
                }
            }
        }); 
    But there must be a faster way to do the same.
    Any other suggestions?

  4. #4
    Sencha User
    Join Date
    Mar 2008
    Posts
    566

    Default

    what do you get when you do this?

    Code:
    var myparams = Ext.getCmp('INDB-form').getForm().getFieldValues();
    var myparams = Ext.applyIf(myparams, Ext.getCmp('INAD-form').getForm().getFieldValues());
    var myparams = Ext.applyIf(myparams, Ext.getCmp('NET-form').getForm().getFieldValues());
    
    console.log(Ext.encode(myparams))

  5. #5
    Sencha User
    Join Date
    Jun 2009
    Location
    Italy
    Posts
    1,395

    Default

    If I write the code you post i get all the params inside a json string

    PHP Code:
    {"a":"a value""b":"b value""c":"c value"
    that is exact what I wanted, so I try to write the following code:

    PHP Code:
    var myparams Ext.getCmp('INDB-form').getForm().getFieldValues();
        var 
    myparams Ext.applyIf(myparamsExt.getCmp('INAD-form').getForm().getFieldValues());
        var 
    myparams Ext.applyIf(myparamsExt.getCmp('NET-form').getForm().getFieldValues());

         
    Ext.Ajax.request({
            
    method'post',
            
    url'setup.php',
            
    params: [ 
                
    Ext.encode(myparams)
            ],
            
    success: function(responseopts) {
                if (
    response.responseText == 'undefined') {
                    
                    
                }
            }
        }); 
    but if I open firebug to see what is send over the server that is what i see as my params

    PHP Code:
    {"a":"a value""b":"b value""c":"c value"
    and not as i expect

    PHP Code:
    a       :value a
    b       
    :value b
    c       
    :value c 
    in fact if, server side i try to write the value of param a

    PHP Code:
    echo $_POST["a"]; 
    I got the following error

    PHP Code:
    Notice:  Undefined indexa in setup.php on line 13 
    so the params are not send correctly to the server.

  6. #6
    Sencha User
    Join Date
    Mar 2008
    Posts
    566

    Default

    Have you tried just looping thru each form field and creating your own param list?

  7. #7
    Sencha User
    Join Date
    Jun 2009
    Location
    Italy
    Posts
    1,395

    Default

    Do you have a quick example on how to do it?

  8. #8
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Why don't you just have one form, which contains Containers? Just submit the form.

  9. #9
    Sencha User
    Join Date
    Jun 2009
    Location
    Italy
    Posts
    1,395

    Default

    Quote Originally Posted by Animal View Post
    Why don't you just have one form, which contains Containers? Just submit the form.
    Hi Animal, my page has a wizard like structure, so every step has it's own form.
    After some validation I have to send every step param inside a single AjaxCall without "bounce" from server and client making a request for every step form.
    Do you have any suggest?

  10. #10
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    No, every step has its own Container

    The whole is encapsulated in a FormPanel

Page 1 of 2 12 LastLast

Similar Threads

  1. Order of ajaxrequest filling multiple stores
    By wvmaaren in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 15 Jul 2009, 5:08 AM
  2. Single XML request, setValues to multiple forms?
    By intrinsical in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 18 Feb 2008, 11:56 PM
  3. Multiple submit buttons in a single form ?
    By offer in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 12 Jan 2008, 9:46 PM
  4. Multiple ajaxRequest on 1 page
    By edynas in forum Ext 1.x: Help & Discussion
    Replies: 4
    Last Post: 27 Jun 2007, 7:34 AM

Posting Permissions

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