Hi,
I’m tryin to validate the phone number in my shopify contact form. It has to start with the digits 6,7,8 and 9 and has to be 10 characters in length.
I would like to validate it within the html part of my code using liquid other than using javascript.
Below is my code for the form.
{% form ‘contact’ %}
{% if form.posted_successfully? %}
{% endif %}
{{ form.errors | default_errors }}
{% assign name_attr = ‘contact.form.name’ | t | handle %}
{{ ‘contact.form.name’ | t }}
{{ ‘contact.form.email’ | t }}
{% assign name_attr = ‘contact.form.phone’ | t | handle %}
{{ ‘contact.form.phone’ | t }}
{% endform %}
Any help would be great.
Thanks
Sagar
1 Like
@sagarsubbaiah
Thanks for post.
can you please try this code.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/tel
1 Like
Hi @sagarsubbaiah , I am creating a contact form with phone number filed but I can’t collect the phone.
This field didn’t appear in the Shopify admin.
Can you collect the phone number?
I have try this code to collect phone but it didn’t work.
Could you help me? Thanks a lot.
Hi @Sofia1234
You can make the following changes
Refer https://www.w3schools.com/html/html_form_input_types.asp for more details.
Thanks
Sagar
Hi @sagarsubbaiah ,
Thanks for your response.
I have tried, but it didn’t work.
I can’t collect the phone.
Could you show me how to collect it. Thanks a lot
Best regards,
Sofia
1 Like
Hey @Sofia1234
probably too late to answer but this worked for me:
{{ customer.default_address.phone }}
Here’s the sample code for the input field:
<input class="#form-input" autocomplete="tel" type="tel" id="ContactForm-phone" name="contact[phone]" value="{% if form.phone %}{{ form.phone | escape }}{% elsif customer %}{{ customer.default_address.phone | escape }}{% endif %}" placeholder="{{ 'templates.contact.form.phone' | t }}">
NOTE: This only extracts the phone number from the default_address.
So, you need to extract the default_address name, email and other details too.
{{ customer.default_address.name }} <!-- get Name from Default Address -->
{{ customer.default_address.email }} <!-- get Email from Default Address -->
Sample Output: