Ad

What Is The Best Way To Place 2 Forms On The Same Page?

- 1 answer

What is the best way to place 2 identical forms on the same page, but use the same form action and fields for each form? How can I keep response messages in the respective form area from which the data was submitted?

I'd have one form in the footer of my site, and one form in a popup on the home page of my site. I'm using a hidden div and Magnific to open the popup containing the same code from the form that is located at the footer. Essentially, both form do the same thing, and utilize the same form action.

I do not have access to the form action, or the code in the form action page.

Currently, the forms existing on the same "page" are no problem, but when I submit an email on one form, the errors and success messages show up on both the popup form as well as in the footer form.

I've read that this may be possible to do with ajax, but for completeness sake, I want to make sure that I'm building that I'm doing what I can with the form html, before moving on to studying ajax for this.

Ad

Answer

Sadly there is no nice html/liquid solution for this.

The only way is to use cookies in order to save information which form was submitted and show the error message only for that form instead of the two ones.

AJAX is not a good solution because of the Google Recaptch-a when you submit the form more than once, which is a real pain in the a** since there is no way to disable it and the form will fail if you try to submit it with ajax.

The easiest solution is to use cookies, other option is to rely on an APP for this, but it may be an overkill for this.

Forms in Shopify are... how to put it nicely... dumb... basic... not developer friendly or just not made to be tweaked in any sort of way ( excluding the front-end ).

Ad
source: stackoverflow.com
Ad