2

I have a frontend form that has a select list for language. This field will allow for one language to be selected. In the backend I have a field set up for my entries as a category field populated by country categories set as required. I can not seem to get the database to update this category field from my frontend form. The select field is set up as follows for the form field handle language.

<select id="language" name="fields[language]">
    <option value="English">English</option>
    etc
</select>

Anything I am missing to get this to populate correctly.

Cheers

4

Couple things. First, I believe you need to add an extra set of brackets to the name attribute. The reason being that category fields (as well as all 'related' fieldTypes) store more than one element, even if as in this case there is only one category being assigned. Secondly you'll need to assign the category id as the value.

<select id="language" name="fields[language][]">
    {% for category in craft.categories.group('languages') %}
         <option value="{{ category.id }}">{{ category.title }}</option>
    {% endfor %}
</select>
  • no I tried that and it made no difference! – Lettie May 20 '15 at 15:43
  • Sorry. Haven't had coffee yet. I wasn't looking at what you were assigning as the value — you'll want to use the category id for this. I updated the answer. – Douglas McDonald May 20 '15 at 16:13
  • Great! Sorry I missed that the first time. – Douglas McDonald May 20 '15 at 16:25

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.