SEO, AdWords, affiliates, advertising, and promotions
When I sign up for the newsletter with my email for the first time, everything appears correct. But when I submit the same email for the second time, the page just refreshes. I want to show an error that says, "You are already our subscriber."
Can it help me with this?
Hi @nikhil1802
You can modify Shopify's newsletter signup form to show an error message.
In the Theme go to Edit Code and replace the existing code with below. Please let me know if this works-
<form method="post" action="{{ routes.root_url }}contact#ContactForm" id="newsletterForm">
<input type="email" name="contact[email]" id="newsletterEmail" placeholder="Enter your email" required>
<button type="submit">Subscribe</button>
<p id="newsletterError" style="color: red; display: none;">You are already our subscriber.</p>
</form>
<script>
document.getElementById("newsletterForm").addEventListener("submit", function(event) {
event.preventDefault(); // Stop the form from submitting immediately
var email = document.getElementById("newsletterEmail").value;
fetch('/contact?email=' + encodeURIComponent(email))
.then(response => response.text())
.then(data => {
if (data.includes("already subscribed")) { // Adjust this based on your theme's error message
document.getElementById("newsletterError").style.display = "block";
} else {
this.submit(); // Submit the form if email is not found
}
})
.catch(error => console.error('Error:', error));
});
</script>
Dotsquares Ltd
Problem Solved? ✔ Accept and Like solution to help future merchants.
It's not working
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025