1

I have a form with a checkbox field. I want the options of the checkbox to be pulled from an entry field.

My custom field template is below but it wont pass validation. I guess this is because Sprout looks for the option values to validate but as they are populated from an entry it wont pass??

At the moment the example below is successfully displaying the entry data as options in the checkbox, it just wont allow me to submit the form.

{% if handle == "checkboxes1" %}

        <div
                {%- if id %} id="{{ id }}"{% endif %}
                {%- if class %} class="{{ class }}"{% endif %}>

            {% if name is defined and (name|length < 3 or name|slice(-2) != '[]') %}
                <input type="hidden" aria-hidden="true" name="{{ name }}" value="">
            {% endif %}             

                {% for date in entry.eventOccurrences %}                            

                <label for="checkboxes1-{{ loop.index }}">


                        <input type="checkbox"
                        data-value="{{ date.date }}"
                                {%- if name %} name="checkboxes1"{% endif %}
                                {%- if id %} id="checkboxes1-{{ loop.index }}"{% endif %}
                                {%- if value %} value="value-{{ loop.index }}"{% endif %}
                        >

                        &nbsp;{{ date.date }}||

                </label>

            {% endfor %}
        </div>

{% endif %}

1 Answer 1

1

The best way to debug a form field using custom HTML is to output the field you want via the default displayForm tag and copy the code from there as a starting point:

{# Output your checkboxes field here and look at the code generated #}
{{ craft.sproutForms.displayForm('yourFormWithACheckbox') }}

Test with the default code that is output as your custom HTML and if that works, adjust from there.

In general, we recommend using custom HTML with caution as it can increase the complexity of the code on the front-end a great deal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.