How do I make additional fields required in the Contact form?

Hello Dev Community!

It seems that the validation for the email field in Contact form happens server side in Dawn. Is there an easy way to extend that to other form fields?
I know I could add “required” attribute to the input fields, but that would use built in browser validation, which looks different than the existing email field validation.

Thanks!

Have you tried, adding required to other fields?
I am not sure but I am guessing it will work as the email fields since pretty much the same code must be handling form submission in any theme.

Yes, I did. It works, but it doesn’t look great. It uses built -in browser validation, which varies by the browser and looks different from the email validation error.
That prevents the form to be submitted, so the server side validation never runs.
According to the docs, only email is required by default:

Thank you for pointing this out. I am fairly new to Shopify and learning bit by bit. This will be certainly something to remember and will save me a lot of time from debugging this unsuccessfully.

Hoping there’s a workaround to this or may be Shopify just come up with an feature update on this one.

Thanks anyways

1 Like

Hi Marianna,

There’s currently no method to make other fields required in the same way as the email field - ie: you’ll need to rely on the regular browser validation, which will appear differently as you pointed out.

1 Like