Coding for Product Inquiry Form

Solved

Coding for Product Inquiry Form

shopworthwhile
Excursionist
16 1 6

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 %}

Accepted Solution (1)

shopworthwhile
Excursionist
16 1 6

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. 

View solution in original post

Replies 2 (2)

Guleria
Shopify Partner
3953 791 1123

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

 

- Drop an email   if you are looking for quick fix or any customization
- Email: guleriathakur43@gmail.com Skype: live:navrocks1
- Try GEMPAGES a great page builder

shopworthwhile
Excursionist
16 1 6

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.