3

I have read a few docs about front-end forms such as the Checkbox field docs.

Although that doc doesn't seem to give an example of what I need.

I have a 'categories' field type. I am creating a front-end form that will need to submit what is checked to the entry. I have tried a few different ways and can't get it to work. This is the last code I tried:

<label for="designTags">Design Tags</label>

{% set categories = craft.categories.group('designs') %}

{% for category in categories %}
    <input type="checkbox" id="designTags" name="fields[designsTags][]" value=" {{ category.id }}"> {{ category.title }} </input> <br />
{% endfor %}

I also tried changing category.title to category.id, but no luck with that either.

And before that, I tried something similar to the code at the bottom of this page (using the option.value) and it still wouldn't work.

Any help you can give is greatly appreciated! :)

1

I just tried your code and it worked.

Is your entry getting saved at all? If not I assume there might be another error. Add this to your code to output all form errors:

{% if entry is defined %}
    {{ dump(entry.getErrors()) }}
{% endif %}

Although it didn't made a difference in my test, you should remove the space to be sure:

value="{{ category.id }}"
  • Using the dump didn't return any errors. The entry is being saved in the CP and normal text fields such as <label for="websiteUrl">Website URL</label> <input id="websiteUrl" name="fields[websiteUrl]"></input> are populated, but nothing from the checkbox categories field type gets saved to the entry in the CP. I also want to mention that I am using the Guest Entries plugin for the front-end form if that makes a difference. – Angela Jul 12 '14 at 19:19
  • Could you deactivate the GuestEntry-plugin, log in as admin, and check again? – Victor In Jul 13 '14 at 12:14
  • Unfortunately that didn't work either. It just seems to be an issue with that Categories Field Type - anything I select is never published to the entry in the CP. Other fields come through just fine. I also checked the permissions and the user has the proper permissions. I also changed the plugin to my admin as author - cl.ly/image/1F2Q2i1E0U15 - and it still does the same thing. I noticed that there is no "Posted Date" with these entries either. Not sure if that is related, but seems strange that the posted date isn't coming through either. Thanks for the help! – Angela Jul 14 '14 at 1:41
1

I just wanted to let you know that I figured this out. I had the section handle in craft.categories.group instead of the category handle. I had just gone through everything again to make sure things were matching up and that's when I found it. Some of my category / section / field names were too similar to each other so too easy to swap out. I just made some tweaks to that to prevent this in the future. Thank you for all of the help and suggestions. So glad that's out of the way and figured out. :)

Thanks!

  • Glad you got it sorted :) – Victor In Jul 14 '14 at 10:39

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.