I am trying to load some options in to a checkbox list from another entry so that a user and save select them form a checkbox list but I am unable to save the Entry Form with their selection.

I have created the registeredOccurances checkbox field in the Section, it has no options set as I want to set them on the entry form.

<input type="hidden" name="fields[registeredOccurances]" value="">    
    {# Load rows from SuperTable in to checkbox list #}
    {% for block in entry[dateFieldHandle] %}
        <label><input type="checkbox" value="{{ loop.index }}" name="fields[registeredOccurances][]"> {{ block.date }}</label>
    {% endfor %}

    {% if entry is defined %}
        <p>{{ dump(entry.getErrors()) }}</p>
    {% endif %}

The dump is outputting the below, can someone help to interpret it?

array(1) { ["registeredOccurances"]=> array(1) { [0]=> string(33) "Registered Occurances is invalid." } }

Thanks for your help :)


Could this be a reserved word? Generally I access fields using entry.registeredOccurances is there a reason you are using fields[registeredOccurances] and entry[dateFieldHandle]?

  • 1
    fields[registeredOccurances] is the correct name for the input, that's how you populate fields in post requests. You can access object properties in Twig with array syntax as well. Sometimes it's even necessary to do that. His error occurs because the default select fields are not supposed to have dynamic values. Since they can't be populated to "text". In the cp you would only see values from 0-xxx with his way because there is no label related to the selected value thus it's forbidden to do that. One has to dynamically change the options of the field before you can save such attributes Jun 7 '18 at 17:48
  • thanks, I did not know that about craft. can you repost this as an answer to the question? I will upvote for you Jun 7 '18 at 17:51
  • Thanks for your input guys. Do you think this is going to be achievable out of the box or will require a plug-in. I was hoping it would be very straight forward!
    – Mark
    Jun 7 '18 at 18:52

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.