Contact form drop down - Warehouse theme i wanit a required field

Hi I ve added the below to my contact form

Im interested in

Does anyone know how to make it a required field ??

the rest of my fields are like this

{{ 'contact.form.phone' | t }}
1 Like

Hello @Lil1977 ,

Greetings for the day

Below is the code to make

Hi thanks, that doesnt seem to work , ive tried adding that ‘required’ it srtill send without me slecting a drop down ?

@Lil1977

I am sorry for that. Can you confirm your button is “submit” and not a regular “button” ? It should look like :


You can share the contact form URL here if you can

Thanks

Hi here is the page code..

button is
{{ ‘contact.form.submit’ | t }}
{%- endform -%}

page code ..

{%- form 'contact', class: 'form' -%} {%- if section.settings.form_heading != blank -%}

{{ section.settings.form_heading | escape }}

{%- endif -%}

{%- if form.posted_successfully? -%}

{{ 'contact.form.successfully_sent' | t }}

{%- endif -%}

{%- if form.errors -%}

    {%- for field in form.errors -%} {%- if field == 'form' -%}
  • {{ form.errors.messages[field] }}
  • {%- else -%}
  • {{ form.errors.translated_fields[field] | capitalize }} {{ form.errors.messages[field] }}
  • {%- endif -%} {%- endfor -%}
{%- endif -%}
{{ 'contact.form.name' | t }}
{{ 'contact.form.phone' | t }}
Im interested in
{{ 'contact.form.email' | t }}

{%- for block in section.blocks -%}
{%- assign field_title = block.settings.title -%}

{%- if field_title == blank -%}
{%- capture field_title -%}Custom field {% increment custom_field %}{%- endcapture -%}
{%- endif -%}

{%- if block.type == ‘text’ -%}

{%- if block.settings.use_long_text -%} {{ block.settings.title | escape }} {%- else -%} {{ block.settings.title | escape }} {%- endif -%}
{%- elsif block.type == 'dropdown' -%} {%- assign values = block.settings.values | split: ',' -%}

{%- if values == empty -%}
{%- continue -%}
{%- endif -%}

{%- render 'icon', icon: 'arrow-bottom' -%}

{{ block.settings.title | escape }}

{%- endif -%} {%- endfor -%}
{{ 'contact.form.message' | t }}

{{ ‘contact.form.submit’ | t }}
{%- endform -%}

{%- if section.settings.show_store_info -%}

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

{{ section.settings.store_heading | escape }}

{%- endif -%}

{%- if section.settings.store_image -%}

{{ section.settings.store_image.alt | escape }}
{%- endif -%}

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

{{ section.settings.store_info }}
{%- endif -%}
{%- endif -%}

{% schema %}
{
“name”: “Contact form”,
“settings”: [
{
“type”: “header”,
“content”: “Form”
},
{
“type”: “text”,
“id”: “form_heading”,
“label”: “Heading”
},
{
“type”: “header”,
“content”: “Store info”
},
{
“type”: “checkbox”,
“id”: “show_store_info”,
“label”: “Show store info”,
“default”: false
},
{
“type”: “text”,
“id”: “store_heading”,
“label”: “Heading”,
“default”: “Find us”
},
{
“type”: “image_picker”,
“id”: “store_image”,
“label”: “Store image”,
“info”: “700 x 500px .jpg recommended”
},
{
“type”: “richtext”,
“id”: “store_info”,
“label”: “Text”
}
],
“blocks”: [
{
“type”: “text”,
“name”: “Text field”,
“settings”: [
{
“type”: “text”,
“id”: “title”,
“label”: “Name”,
“label”: “Phone”,
“default”: “Custom field”
},
{
“type”: “checkbox”,
“id”: “use_long_text”,
“label”: “Use long text”,
“default”: false
},
{
“type”: “checkbox”,
“id”: “is_required”,
“label”: “Field is required”,
“default”: false
}
]
},
{
“type”: “dropdown”,
“name”: “Dropdown”,
“settings”: [
{
“type”: “text”,
“id”: “title”,
“label”: “Name”,
“label”: “Phone”,
“default”: “Custom field”
},
{
“type”: “text”,
“id”: “values”,
“label”: “Values”,
“info”: “Separate each value by a comma.”,
“default”: “value 1, value 2, value 3”
}
]
}
]
}
{% endschema %}

Hello @Lil1977

As per my understanding, it is not working because there is no value in the option. It requires 1 blank value to work.

I corrected the code. Please try the below code it should work :


Output :

Thanks

2 Likes

Hi yes thast works , many thanks how do i get a label next to the drop down to say sometning like " Im intetested in" . thanks for you help

@Lil1977 I edited my previous answer, Added code to the display label. Please see if it helps

actaully its on i can use it as alabel inside the drop dow, thanks for you help

See coding is a super easy thing :sweat_smile:

Glad to help @Lil1977

Thanks

1 Like