Skip Navigation

[Resolved] Multiple form, one submit button

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to submit multiple forms on the same page with a single click?

Solution:
This is only possible when the forms are set to update via ajax and upon submission they keep displaying the form (rather than redirect to another page or display a message).

You would need to use JavaScript such as the following, which you would add to one of the forms, and which assumes that the submit buttons in each form have a .btn-submit class added:

( function( $ ) {
    $( document ).ready( function(){
 
        $('.btn-submit').on( "click.tssupp", function(e){
 
            var others = $('.btn-submit').not(this);
 
            $('.btn-submit').off( "click.tssupp");
             
            others.click();
 
        });
 
    });
})( jQuery );
This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by minanA 5 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#1147448

We display multiple form in one page. How to just use one only submit button for all form displayed?

#1147857

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

You would need a JavaScript solution where clicking on one button simulated a click on each of the other buttons.

This solution would only work where the forms are submitted via ajax, it wouldn't be possible if the forms submit via a page refresh.

Also, the forms would each need to have the setting to continue displaying the form.

Any other setting would navigate away from the page as soon as one form submission had completed, but before the others had.

Before I suggest what code you might use, does those settings make sense for your scenario? That clicking one button would submit all forms, but without updating the page and still showing the forms?

#1147991

Hi Nigel,

Its OK:
- submitted via ajax
- still showing the forms
because this multiple form is not intended for random visitor.

Please, i need your suggestion.

#1148007

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

In that case you should be able to use code such as the following, which you need to add only once to the page (so you could add it to the custom JS section of *one* of your forms).

( function( $ ) {
	$( document ).ready( function(){

		$('.btn-submit').on( "click.tssupp", function(e){

			var others = $('.btn-submit').not(this);

			$('.btn-submit').off( "click.tssupp");
			
			others.click();

		});

	});
})( jQuery );

You need a common class that can be used to target the submit buttons of these forms. The above code relies on you editing the forms and adding the class "btn-submit" to the submit button field.

#1148231

Hi Nigel,

My issue is resolved now, with some modifications. Thank you!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.