How can I make the email field optional in my custom form?

I am using below code for custom form and getting error of “Email is invalid” if not filled.

is there any option to make email as an optional?
Here is shopify documentation

{% form 'contact' %}
  {{ form.errors | default_errors }}

  <div class="first-name">
    <label for="first-name">First name</label>
    <input type="text" name="contact[first_name]" id="first-name" />
  </div>

  <div class="last-name">
    <label for="last-name">Last name</label>
    <input type="text" name="contact[last_name]" id="last-name" />
  </div>

  <div class="phone">
    <label for="phone">Phone</label>
    <input type="tel" name="contact[phone]" id="phone" />
  </div>

  <div class="email">
    <label for="email">Email</label>
    <input type="email" name="contact[email]" id="email" />
  </div>

  <div class="order-number">
    <label for="order-number">Order number</label>
    <input type="text" name="contact[order_number]" id="order-number" />
  </div>

  <div class="message">
    <label for="message">Message</label>
    <textarea name="contact[body]" id="message"></textarea>
  </div>

  <div class="submit">
    <input type="submit" value="Create" />
  </div>
{% endform %}

You could change input type to text, someone may have a better solution.

<div class="email">
    <label for="email">Email</label>
    <input type="text" name="contact[email]" id="email" />
  </div>

Hi @Grace_01

If you use shopify contact form then “email” filed must need to pass, so if you did not enter valid email it will give you error, so make this field required
like below:


Best regard

Hi @Jasoliya can’t we make email optional ?

no because this field is required, if want to make it optional then you have to do custom logical script, like if user keep email blank then pass your default email in email field so form will send successfully. do this by js code so it will work.

Hi @biznazz101 this doesn’t work