User_FTW
User_FTW

Reputation: 524

Shopify form file upload

I have this liquid on a page template:

{% form 'contact' %}

{% if form.posted_successfully? %}
    <p class="note success">Success!</p>
{% endif %}

{{ form.errors | default_errors }}

<p>
    <label for="ContactFormName">Name</label>
    <input type="text" id="ContactFormName" name="contact[name]" value="{% if form[name_attr] %}{{ form[name_attr] }}{% elsif customer %}{{ customer.name }}{% endif %}" required>
</p>

<p>
    <label for="ContactFormCV">Upload CV</label>
    <input type="file" id="ContactFormCV" name="contact[cv]" required />
</p>

{% endform %}

The problem is that when a file is selected for upload and the form submitted, the email that is received only shows the file name. Ideally it should have the file attached, or a link to the file.

If I change the form tag to this...

{% form 'contact', enctype: 'multipart/form-data' %}

...I get this error when submitting a form:

There was a problem loading this website
Try refreshing the page.
If the site still doesn't load, please try again in a few minutes.

How can I get this to work?

Note: This form is being used on a custom template in the templates directory (page.employment.liquid).

enter image description here

Upvotes: 0

Views: 2215

Answers (1)

Alice Girard
Alice Girard

Reputation: 2173

As far as I know, Shopify liquid forms do not accept file input type.

You have basically two solutions:

  • Use an external app
  • Code an Ajax request to upload file to an external server via a PHP file as explained here (keeping in mind that there is a huge work to do to sanitize and secure upload process on your server)

HTH

Upvotes: 1

Related Questions