Shopify表单文件上传

发布于 2025-02-09 18:11:13 字数 1238 浏览 0 评论 0原文

我在页面模板上有此液体:

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

问题是,当选择文件上传和提交的表单时,收到的电子邮件仅显示文件名。理想情况下,它应该附加文件或文件链接。

如果我将表单标签更改为此...

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

...提交表单时会遇到此错误:

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.

如何使此错误工作?

注意:此表格正在模板目录(page.employment.liquid)中的自定义模板上使用。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摘星┃星的人 2025-02-16 18:11:13

据我所知,Shopify液体表格不接受文件输入类型。

您基本上有两个解决方案:

  • 使用外部应用代码
  • AJAX请求通过PHP文件上传文件,如在这里(请记住,请记住一个有一个巨大的工作需要消毒和保护服务器上的上传过程)

HTH

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文