Hi, I´ve duplicated the contact form and added this to a popup that opens up when customers click on a contact icon on my site. Everything is working as wanted except from when my customers are supposed to enter their details and send the form. When clicking send I´m being redirected to another page. How can I implement both recaptcha, error messages and success messages inside the popup without being redirected to another page?
Here is the code:
{{ "section-contact-form.css" | asset_url | stylesheet_tag }}
{%- style -%} .section-{{ section.id }}-padding { padding-top:
{{ section.settings.padding_top | times: 0.75 | round: 0 }}px; padding-bottom:
{{ section.settings.padding_bottom | times: 0.75 | round: 0 }}px; } @media
screen and (min-width: 750px) { .section-{{ section.id }}-padding { padding-top:
{{ section.settings.padding_top }}px; padding-bottom:
{{ section.settings.padding_bottom }}px; } } {%- endstyle -%}
##
{{ section.settings.heading | escape }}
{{section.settings.contact_paragraph}}
{{section.settings.contact_email}}
{{section.settings.contact_address}}
{%- form 'contact', id: 'ContactForm', class: 'isolate' -%} {%- if
form.posted_successfully? -%}
{% render 'icon-success' %}
{{ "templates.contact.form.post_success" | t }}
{%- elsif form.errors -%}
##
{% render 'icon-error' %}
{{ "templates.contact.form.error_heading" | t }}
- {{ form.errors.translated_fields["email"] | capitalize }}
{{ form.errors.messages["email"] }}
{%- endif -%}
{%- if form.errors contains 'email' -%}
<small>
{{ "accessibility.error" | t }}
{% render 'icon-error' %}{{
form.errors.translated_fields["email"] | capitalize
}}
{{ form.errors.messages["email"] }}
</small>
{%- endif -%}
{%- endform -%}
{% schema %} { "name": "t:sections.contact-form.name", "tag": "section",
"class": "section", "settings": [ { "type": "text", "id": "heading", "default":
"Contact form", "label": "Heading" }, { "type": "select", "id": "color_scheme",
"options": [ { "value": "accent-1", "label":
"t:sections.all.colors.accent_1.label" }, { "value": "accent-2", "label":
"t:sections.all.colors.accent_2.label" }, { "value": "background-1", "label":
"t:sections.all.colors.background_1.label" }, { "value": "background-2",
"label": "t:sections.all.colors.background_2.label" }, { "value": "inverse",
"label": "t:sections.all.colors.inverse.label" } ], "default": "background-1",
"label": "t:sections.all.colors.label" }, { "type": "header", "content":
"t:sections.all.padding.section_padding_heading" }, { "type": "range", "id":
"padding_top", "min": 0, "max": 100, "step": 4, "unit": "px", "label":
"t:sections.all.padding.padding_top", "default": 36 }, { "type": "range", "id":
"padding_bottom", "min": 0, "max": 100, "step": 4, "unit": "px", "label":
"t:sections.all.padding.padding_bottom", "default": 36 },
{"type": "richtext",
"id": "contact_paragraph",
"default": "
Avsnitt
",
"label": "Avsnitt med tekst"
},
{"type": "text",
"id": "contact_email",
"default": "hei@epost.no",
"label": "Epost"
},
{"type": "text",
"id": "contact_address",
"default": "Adresse",
"label": "Adresse"
}
], "presets": [ {
"name": "CONTACT SECTION" } ] } {% endschema %}
var contactBtn = document.querySelector(".open-popup");
var contactSectionBg = document.querySelector(".contact-section-background");
var closeBtn = document.querySelector(".exit-icon");
var contactForm = document.querySelector(".contact");
contactBtn.addEventListener("click", function () {
contactSectionBg.classList.add("bg-active");
});
closeBtn.addEventListener("click", function () {
contactSectionBg.classList.remove("bg-active");
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
contactSectionBg.classList.remove("bg-active");
}
});