1

My front-end new entry form works, but when I add the complexity of a dropdown to the mix - it error's and doesn't save the entry. (I found this out with trial and error, removing fields until I found the culprit - the dropdowns)

I'm unsure what errors it's returning, but I'm sure something may be off with the code.

  {% macro errorList(errors) %}
            {% if errors %}
                <ul class="errors">
                    {% for error in errors %}
                        <li>{{ error }}</li>
                    {% endfor %}
                </ul>
            {% endif %}
        {% endmacro %}

        {% from _self import errorList %}

        <form method="post" accept-charset="UTF-8" enctype="multipart/form-data">
            {{ csrfInput() }}
            <input type="hidden" name="action" value="entries/save-entry">
            {{ redirectInput('/listings/') }}
            <input type="hidden" name="sectionId" value="1">
            <input type="hidden" name="enabled" value="1">

            <div class="form-group">
              <label>Demographic</label>
              <select class="form-control" id="listingType" name="fields[demographic]">
                {% set demographicField = craft.fields.getFieldbyHandle('demographic') %}
                {% for option in demographicField.settings.options %}
                  <option>{{ option.label }}</option>
                {% endfor %}
              </select>
            </div>

            <button class="btn btn-primary btn-md semi-bold" type="submit">Create Listing</button>

        </form>
2

On your dropdown field's name, you need a [] on the end for it to submit properly:

name="fields[demographic][]"

As mentioned in this answer, the dropdown field is basically an array of options, so you need that empty array on the end for them to be stored in.

| improve this answer | |

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.