2

I a musing a front-end form to create an entry in the CP. In my form I am using a SuperTable that contains two fields/blocks.

  • Size - [text input]
  • Measurement - [dropdown]

Here is what my template looks like:

<div class="row">
    <input type="hidden" name="fields[lotSize]">
    <input type="hidden" name="fields[lotSize][new1][type]" value="1">

    <div class="col-xs-6">
        <div class="form-group">
            <label for="lotSize">Lot Size</label>
            <input type="text" class="form-control" name="fields[lotSize][new1][fields][size]">
        </div>
    </div>
    <div class="col-xs-6">
        <label for="measurement">Measurement</label>
        <select name="fields[lotSize][new1][fields][measurement]">
            {# Loop through the values instead of hard-coding #}
            <option value="">Select</option>
            <option value="squareFeet">Square Feet</option>
            <option value="acres">Acres</option>
        </select>
    </div>
</div>

I've been reading through Updating a Super Table field from a front end form and have tried this:

{% set fieldHandle = 'lotSize' %}
{% set field = craft.fields.getFieldByHandle(fieldHandle) %}
{% set blocktype = craft.superTable.getSuperTableBlocks(field.id)[0] %}

...But I'm not sure where to go next to get to the measurement field.

I have attached a screenshot of my CP page to help show what I am trying to accomplish. Thank you for any suggestions!

enter image description here

3

You'll likely want to do something like this:

{% for fieldtype in blocktype.getFieldLayout.fields %}
    {% set field = fieldtype.field %}

    Handle: {{ field.handle }}

    {% if field.type == 'Dropdown' %}
        {% for option in field.settings.options %}
            Label: {{ option.label }}
            Value: {{ option.value }}
        {% endfor %}
    {% endif %}
{% endfor %}

Essentially, this loops through all the sub-fields in your Super Table field, and for each field, you can make any sort of conditional you like in order to handle each fields content.

  • Exactly the shove I needed. {% if field.type == 'Dropdown' %} was it. Thank you! – Damon May 15 '17 at 4:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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