Detect if a form has any required fields? #2812
Answered
by
engram-design
chrismlusk
asked this question in
Q&A
-
|
I have a project where we've been directed to add instructions that explain what the asterisks are above each form with a required field. Is there a way to detect if a form has any required fields at render time? A property or helper so we can add something like: {% if form.hasRequiredFields %}
<div>* Indicates a required field</div>
{% endif %}
{{ craft.formie.renderForm(form, renderOptions) }} |
Beta Was this translation helpful? Give feedback.
Answered by
engram-design
Apr 23, 2026
Replies: 1 comment 1 reply
-
|
There's no property or helper, but looping is the quickest way. {% set hasRequiredFields = false %}
{% for field in form.getFields() %}
{% if field.required %}
{% set hasRequiredFields = true %}
{% endif %}
{% endfor %} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
chrismlusk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's no property or helper, but looping is the quickest way.
{% set hasRequiredFields = false %} {% for field in form.getFields() %} {% if field.required %} {% set hasRequiredFields = true %} {% endif %} {% endfor %}