4

Is is possible to assign a category via a frontend Guest Entry form.

I tried

<input type="hidden" name="fieldHandle" value="SomeExistingCategorySlug">

But that did not work.

2

Simply put, a Categories field is an array containing category ids, and your form needs to send it that way:

<input type="hidden" name="fields[fieldHandle][]" value="100">

Adding brackets to your field-handle submits the value as an array, and 100 is the id of the category.

  • Where do I find the category id? – AbbeyDesign Aug 11 '14 at 17:50
  • You can either output it in your template: {{ craft.categories.group('group_handle').slug('some_slug').first.id }}, or go to "Backend -> Categories" inspect a category, and look for the data-id attribute. – Victor In Aug 11 '14 at 18:03
  • I had tried using the data-id before I asked. Sorry, should have specified. Form sends, all data is recorded, just not the category. – AbbeyDesign Aug 11 '14 at 18:10
  • Try creating a plugin with a guestEntries.beforeSave-event and dump-die all the data, to check if it gets send correctly. – Victor In Aug 11 '14 at 18:33
  • Replaced name="fieldHandle[]" with name="fields[fieldHandle][]" and Victor's solution worked. – AbbeyDesign Aug 13 '14 at 13:27

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.