Good evening Shopifyer’s
I have one page with 3 contact forms, all with unique IDs set like so:
{% form 'contact', id: section.settings['form-id'] %}
I am having issues getting the form errors because each form is displaying the form errors because the form object is being picked up.
{%- if form.errors -%}
That is present between each form tag and so is showing up in all the forms.
Is there a way to differentiate between the form errors being received like checking what form ID they have/relate to?
Any pointers to get that working?
Many thanks
Evening, this line gives all forms the same exact same ID attribute value, unless they are all unique sections with unique settings.
{% form 'contact', id: section.settings['form-id'] %}
Generally it should be
{%- assign form_id = section.settings['form-id'] | append: '-' | append: section.id -%}
{% form 'contact', id: form_id %}
How dawn’s handles product form name-spacing
https://github.com/Shopify/dawn/blob/main/sections/main-product.liquid#L69
Beyond that I don’t think form_errors return any identifying reference information about a form
https://shopify.dev/docs/api/liquid/objects/form_errors , just spit out the object and see if it does.
You may just need to track the state of which form was submitted to associate the errors to the proper form. Spitball - for javascriptless maybe see if you can set a cart-attribute using return_to redirects to indicate the “active” form in liquid.
When dot notation would work fine to get a value avoid using square bracket notation.
SBN generally indicates something is being hardcoded like a handle , or the value passed to SBN will be dynamic.
{% form ‘contact’, id: section.settings.form_id %}
Thanks for your time on this Paul.
Actually using the SBN in this line was only being used on one contact form.
{% form 'contact', id: section.settings['form-id'] %}
So I am using this on all the contact forms.
{% form 'contact', id: section.settings.form-id %}
I’m also having issues with the form not persisting the data. It shows up in the URL bar though.
But more specifically, I am constantly getting an invalid email error on this form and not sure why. The email is correct when I enter it. If you can help on this one big thanks!
Hi Sam.
I am having a similar error with my form “I am constantly getting an invalid email error on this form and not sure why. The email is correct when I enter it.”
In my case, I have a new contact form and when submit it I get an email error in the newsletter subscription at the footer, not in the one I have as a field in the contact form.
Were you able to solved your issue? Maybe I can try with a similar solution.
Thanks in advance!
Roger