Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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 -%}
<script src="{{ 'contact-form.js' | asset_url }}" defer="defer"></script>
<div class="open-popup"><i class="fa-solid fa-message"></i></div>
<div class="color-{{ section.settings.color_scheme }} gradient contact-section-background">
<div
class="contact page-width page-width--narrow section-{{
section.id
}}-padding"
>
<i class="exit-icon fa-solid fa-xmark"></i>
<div class="inner-containers info-container">
<h2 class="title title-wrapper--no-top-margin">
{{ section.settings.heading | escape }}
</h2>
<div class="contact-paragraph">{{section.settings.contact_paragraph}}</div>
<div class="contact-details">
<p class="contact-detail"><i class="contact-icon fa-solid fa-envelope"></i>{{section.settings.contact_email}}</p>
<p class="contact-detail"><i class="contact-icon fa-solid fa-location-dot"></i>{{section.settings.contact_address}}</p>
</div>
</div>
<div class="inner-containers contact-form-container">
{%- form 'contact', id: 'ContactForm', class: 'isolate' -%} {%- if
form.posted_successfully? -%}
<div
class="form-status form-status-list form__message"
tabindex="-1"
autofocus
>
{% render 'icon-success' %}
{{ "templates.contact.form.post_success" | t }}
</div>
{%- elsif form.errors -%}
<div class="form__message">
<h2
class="form-status caption-large text-body"
role="alert"
tabindex="-1"
autofocus
>
{% render 'icon-error' %}
{{ "templates.contact.form.error_heading" | t }}
</h2>
</div>
<ul class="form-status-list caption-large" role="list">
<li>
<a href="#ContactForm-email" class="link">
{{ form.errors.translated_fields["email"] | capitalize }}
{{ form.errors.messages["email"] }}
</a>
</li>
</ul>
{%- endif -%}
<div class="contact__fields">
<div class="field">
<input
class="field__input"
autocomplete="name"
type="text"
id="ContactForm-name"
name="contact[{{ 'templates.contact.form.name' | t }}]"
value="{% if form.name %}{{ form.name }}{% elsif customer %}{{
customer.name
}}{% endif %}"
placeholder="{{ 'templates.contact.form.name' | t }}"
/>
<label class="field__label" for="ContactForm-name">{{
"templates.contact.form.name" | t
}}</label>
</div>
<div class="field">
<input
type="tel"
id="ContactForm-phone"
class="field__input"
autocomplete="tel"
name="contact[{{ 'templates.contact.form.phone' | t }}]"
pattern="[0-9\-]*"
value="{% if form.phone %}{{ form.phone }}{% elsif customer %}{{
customer.phone
}}{% endif %}"
placeholder="{{ 'templates.contact.form.phone' | t }}"
/>
<label class="field__label" for="ContactForm-phone">{{
"templates.contact.form.phone" | t
}}</label>
</div>
</div>
<div class="field field--with-error">
<input autocomplete="email" type="email" id="ContactForm-email"
class="field__input" name="contact[email]" spellcheck="false"
autocapitalize="off" value="{% if form.email %}{{ form.email }}{%
elsif customer %}{{ customer.email }}{% endif %}" aria-required="true"
{% if form.errors contains 'email' %} aria-invalid="true"
aria-describedby="ContactForm-email-error" {% endif %} placeholder="{{
"templates.contact.form.email" | t
}}" >
<label class="field__label" for="ContactForm-email"
>{{ "templates.contact.form.email" | t }}
<span aria-hidden="true">*</span></label
>
{%- if form.errors contains 'email' -%}
<small class="contact__field-error" id="ContactForm-email-error">
<span class="visually-hidden">{{ "accessibility.error" | t }}</span>
<span class="form__message"
>{% render 'icon-error' %}{{
form.errors.translated_fields["email"] | capitalize
}}
{{ form.errors.messages["email"] }}</span
>
</small>
{%- endif -%}
</div>
<div class="field">
<textarea
rows="10"
id="ContactForm-body"
class="text-area field__input"
name="contact[{{ 'templates.contact.form.comment' | t }}]"
placeholder="{{ 'templates.contact.form.comment' | t }}"
>
{{- form.body -}}
</textarea>
<label class="form__label field__label" for="ContactForm-body">{{
"templates.contact.form.comment" | t
}}</label>
</div>
<div class="contact__button">
<button type="submit" class="custom-button">
{{ "templates.contact.form.send" | t }}
</button>
</div>
{%- endform -%}
</div>
</div>
</div>
{% 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": "<p>Avsnitt</p>",
"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");
}
});
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025