PDA

View Full Version : submit 2 form from one button



raj_plays
3 Jun 2011, 9:53 AM
Hi,
I have 2 form panels on my page.
The fields of the 2 forms map to columns of the same DB table.
I was wondering if there is a way of submitting both the forms on the click of a single button.
Anyone?

drian
3 Jun 2011, 10:02 AM
hmm, why don't you make a function that wraps both forms .submit()?

function submit(){
form1.submit();
form2.submit();
}

friend
3 Jun 2011, 10:26 AM
To be all technically correct, in case a future n00b reads these posts:



function submit()
{
form1.getForm().submit({
url: 'someUrl1',
success: function(basicForm, action) {
// do something successfully.
},
failure: function() {
// piss & moan effectively.
}
});

form2.getForm().submit({
url: 'someUrl2',
success: function(basicForm, action) {
// do something successfully.
},
failure: function() {
// piss & moan effectively.
}
});
}

raj_plays
3 Jun 2011, 10:27 AM
Thanks, drian.
What I want is data from both the forms to get submitted at once to a server site component.
Basically, concatenate all the fields of the 2 forms and POST to a url.
1 POST only.

Possible?

skirtle
3 Jun 2011, 7:39 PM
You've got a few options.

Personally I'd probably just call:


var values = Ext.apply(form1.getForm().getValues(), form2.getForm().getValues());

and then use Ext.Ajax.request() to submit it.

An alternative would be something like this:


form1.getForm().submit({
params: form2.getForm().getValues(),
...
});

raj_plays
4 Jun 2011, 2:14 AM
Thanks, skirtle.
The first code fits the bill.