Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi all,
I created a liquid code to embed an inquiry form into certain products. It works great, sends the product description over with the message, but I haven't figured out how to have a success message when they hit Submit. This leads to several customers sending duplicate queries because obviously, they don't know it has gone through successfully. Here is code below:
{% form 'contact' %}
{{ form.errors | default_errors }}
<div class="name">
<label for="name">Name<br></label>
<input type="text" name="contact[name]" id="name" />
</div>
<br>
<div class="email">
<label for="email">
Email<br></label>
<input type="email" name="contact[email]" id="email" />
</div><br>
<input type="hidden" id="message" name="contact[product]" value="{{ product.title }}">
<div class="message">
<label for="message">Message<br></label>
<textarea name="contact[body]" id="message"></textarea>
</div>
</div>
<div class="lightly-spaced-row">
<button class="btn" type="submit">SEND</button>
</div>
{% endform %}
Solved! Go to the solution
This is an accepted solution.
Thank you for the responses! It isn't perfect, but it works and shows a message. I ended up using a combination of both of your suggestions in my modifications.
Hello @shopworthwhile ,
Update your code with this one
{% form 'contact' %}
{%- if form.posted_successfully? -%}
// Your success will be here
{%- elsif form.errors -%}
{{ form.errors | default_errors }}
{%- endif -%}
<div class="name">
<label for="name">Name<br></label>
<input type="text" name="contact[name]" id="name" />
</div>
<br>
<div class="email">
<label for="email">
Email<br></label>
<input type="email" name="contact[email]" id="email" />
</div><br>
<input type="hidden" id="message" name="contact[product]" value="{{ product.title }}">
<div class="message">
<label for="message">Message<br></label>
<textarea name="contact[body]" id="message"></textarea>
</div>
</div>
<div class="lightly-spaced-row">
<button class="btn" type="submit">SEND</button>
</div>
{% endform %}
Note: Change this line
// Your success will be here
a/to your need.
Regards
Guleria
This is an accepted solution.
Thank you for the responses! It isn't perfect, but it works and shows a message. I ended up using a combination of both of your suggestions in my modifications.
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025