How to use Taxonomies/Terms in Forms #6510
-
Hey, I want to create a form with a select where the frontend user can choose between options that come from my taxonomy.
But no taxonomy options are shown and also the {{ title }} is not the title of the taxonomy but the forms title. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 20 replies
-
You can make the Taxonomy Terms field type available to use by adding Then you just need to create a view in <div class="o-form__select">
<label class="u-sr" for="{{ handle }}">
{{ display }}
</label>
<select id="{{ handle }}" class="c-select c-select--md" name="{{ handle }}[]" {{ (validate | contains:required) ? 'required="required"' : '' }} {{ multiple ?= "multiple" }}>
<option value>{{ if instructions }}{{ instructions }}{{ else }}Please select...{{ /if }}</option>
{{ taxonomy from="{collections|option_list}" }}
<option value="{{ id }}" {{ if old|in_array:id || old === id }}selected{{ /if }}>{{ title }}</option>
{{ /taxonomy }}
</select>
{{ if error }}
<span class="c-status c-status--error">
{{ error }}
</span>
{{ /if }}
</div> I've only done this with collections but that above should work, might need a few tweaks though |
Beta Was this translation helpful? Give feedback.
You can make the Taxonomy Terms field type available to use by adding
\Statamic\Fieldtypes\Terms::makeSelectableInForms();
your AppServiceProvider boot method.Then you just need to create a view in
resources/views/vendor/statamic/forms/fields/term.antlers.html
and then you can do something like