my dog learned polymorphism
The moose likes Struts and the fly likes How to submit two forms on same page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to submit two forms on same page?" Watch "How to submit two forms on same page?" New topic

How to submit two forms on same page?

Abhishek Anne

Joined: Sep 05, 2011
Posts: 4

0 down vote favorite
share [fb] share [tw]


I have two forms
1> Own Customized Form say form1.
2> Form rendering from third party java script call say form2.

Previously there was only one form
(no third party form) with same fields.
Thus I was submitting it using single submit button.
Lets say I was calling Action1 for my old form.

The third party form has own submit button and it post values (Not all. Only Third Party
values ) to own controller and returns response .

I don't want to ask user to submit twice on same page.

I want to submit both forms on old submit button and hide third party submit button.

I can change the response URL (where to land to get third party form submit response ).

I am thinking to hide third party submit button with css and call click/submit that when I
click old submit button using javascript.

Lets set response landing page for third party to Action1.

But if I land on old action ie Action1 I cant able to get old customized form element?

I am stuck in this scenario.

Can you have any better solution to this?

[Using struts framework and jsp for rendering form.]
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1599
You may not submit two forms, but you can chose to submit how many fields you want to submit. After all that is what you would be wanting to do - submit data.

Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
john lazeraski
Ranch Hand

Joined: Nov 14, 2011
Posts: 76
One way you can do it is using JavaScript and ajax, you can grab all the values of the two forms and build up a single ajax request. ajax requests would work similar to a form submit.. should be easy enough to handle it for one request with one action class. You may need to figure out the 3rd party component fields and modify them in your JS so as to properly auto-populate your own custom bean that the action class can then use.
I agree. Here's the link:
subject: How to submit two forms on same page?
It's not a secret anymore!