お問い合わせフォームの名前入力を必須にしたい

Dawnのお問い合わせフォームに名前入力欄をつくり入力必須にしたいのですが方法がわからずに困っております。

デフォルトで入力必須のメールアドレスのコードをコピペして任意の部分をカスタマイズしましたが、入力せずにそのまま送信してもエラー表示も出ず、送信されてしまいます。

ご教授いただければ幸いです。


{{ ‘section-contact-form.css’ | asset_url | stylesheet_tag }}

{%- style -%}
.section-{{ section.id }}-padding {
padding-top: {{ section.settings.padding_top | times: 0.75 | round: 0 }}px;
padding-bottom: {{ section.settings.padding_bottom | times: 0.75 | round: 0 }}px;
}

@media screen and (min-width: 750px) {
.section-{{ section.id }}-padding {
padding-top: {{ section.settings.padding_top }}px;
padding-bottom: {{ section.settings.padding_bottom }}px;
}
}
{%- endstyle -%}

{%- if section.settings.heading != blank -%}

{{ section.settings.heading | escape }}

{%- else -%}

{{ 'templates.contact.form.title' | t }}

{%- endif -%} {%- form 'contact', id: 'ContactForm', class: 'isolate' -%} {%- if form.posted_successfully? -%}

{% render 'icon-success' %} {{ 'templates.contact.form.post_success' | t }}

{%- elsif form.errors -%}

{% render 'icon-error' %} {{ 'templates.contact.form.error_heading' | t }}

{%- endif -%}
会社名
{{ 'templates.contact.form.name' | t }} * {%- if form.errors contains 'name' -%} {{ 'accessibility.error' | t }} {% render 'icon-error' %}{{ form.errors }} {{ form.errors.messages }} {%- endif -%}
{{ 'templates.contact.form.email' | t }} * {%- if form.errors contains 'email' -%} {{ 'accessibility.error' | t }} {% render 'icon-error' %}{{ form.errors.translated_fields['email'] | capitalize }} {{ form.errors.messages['email'] }} {%- endif -%}
{{ 'templates.contact.form.phone' | t }}
{{- form.body -}} お問い合わせ内容
{{ 'templates.contact.form.send' | t }}
{%- endform -%}

{% schema %}
{
“name”: “t:sections.contact-form.name”,
“tag”: “section”,
“class”: “section”,
“settings”: [
{
“type”: “text”,
“id”: “heading”,
“default”: “Contact form”,
“label”: “Heading”
},
{
“type”: “select”,
“id”: “heading_size”,
“options”: [
{
“value”: “h2”,
“label”: “t:sections.all.heading_size.options__1.label”
},
{
“value”: “h1”,
“label”: “t:sections.all.heading_size.options__2.label”
},
{
“value”: “h0”,
“label”: “t:sections.all.heading_size.options__3.label”
}
],
“default”: “h1”,
“label”: “t:sections.all.heading_size.label”
},
{
“type”: “select”,
“id”: “color_scheme”,
“options”: [
{
“value”: “accent-1”,
“label”: “t:sections.all.colors.accent_1.label”
},
{
“value”: “accent-2”,
“label”: “t:sections.all.colors.accent_2.label”
},
{
“value”: “background-1”,
“label”: “t:sections.all.colors.background_1.label”
},
{
“value”: “background-2”,
“label”: “t:sections.all.colors.background_2.label”
},
{
“value”: “inverse”,
“label”: “t:sections.all.colors.inverse.label”
}
],
“default”: “background-1”,
“label”: “t:sections.all.colors.label”
},
{
“type”: “header”,
“content”: “t:sections.all.padding.section_padding_heading”
},
{
“type”: “range”,
“id”: “padding_top”,
“min”: 0,
“max”: 100,
“step”: 4,
“unit”: “px”,
“label”: “t:sections.all.padding.padding_top”,
“default”: 36
},
{
“type”: “range”,
“id”: “padding_bottom”,
“min”: 0,
“max”: 100,
“step”: 4,
“unit”: “px”,
“label”: “t:sections.all.padding.padding_bottom”,
“default”: 36
}
],
“presets”: [
{
“name”: “t:sections.contact-form.presets.name”
}
]
}
{% endschema %}

emailのinputをコピーして作られたコードは下記でしょうか?


こちらで合っているようでしたら、

おそらく、下記のようにすることで、

一応(※)、必須扱いにできるのではないと思いますが、

いかがでしょうか?


最後に"required"を追加しただけです。

もっと言いますと、inputに"required"がついているだけで、

入力必須扱いになりますので、

メールアドレスのコードをコピーしなくても大丈夫です。

「一応」というのは、

こうした場合、

「送信する」をクリックした際に、

ページ遷移をせずに、

入力必須であることを促すメッセージが表示される(下図)ため、

メールアドレスに入力がない場合の挙動とは異なってしまいます。

参考: http://www.htmq.com/html5/input_required.shtml

なお、上図のスクリーンショットは、Google Chromeのものですが、

FireFoxですと下記のように表示されます。

このように、

ブラウザによって、

未入力時のメッセージのスタイルが異なる点もご留意ください。

詳しく調べていませんが、

このメッセージのスタイルの調整はできなかったように記憶しています。

ご希望の回答になっていないかと思いますが、

参考になるようでしたら幸いです。

(キュー田辺)