1

I'm building my first Sprout Form and I need a tags relational field, but where the user filling in the form can add their own tags, but if similar/matching tags exist then they can select them, like the tags field behaves within the control panel.

Anyone know if that's possible? If not in Sprout Forms, another way?

1

Short answer: yes it's possible. Longer answer: it will probably require some custom development during your implementation to get in place what you're looking for.

Sprout Forms has a Tags Field in the Relations Field section of the Form Builder. On the CP side, it's just a wrapper around Craft's Tag Relations field and will work the same way for Content Admins.

By default, this field just outputs a list of tags in a dropdown for a user to choose from.

But, does the field support submitting new tags? I don't know! As the Form is just receiving POST data I'd start by taking a look at how Craft's Tags field is sending new Tags when entries are saved in the back end and try to update the front end tag input to submit data in the same way and see if it works.

If it does work, the main problem here would then be that you'd like to update your front-end UI. You can do that using Form Template Overrides and override the input field for the Tags field to behave as you wish. As long as you are submitting the POST data in the same format, Sprout Forms doesn't care which field type you use or if you use javascript or a Vue Component to guide your user toward preparing the input for submission.

If it doesn't work, then we could consider that a Feature Request or you could address the problem by building out a custom Tags Field that behaves as you need it to using the Form Field API. You're more than welcome to use Sprout Form's Tags Field as a starting point.

| improve this answer | |
  • Thanks but shame it can't already be done. This will be beyond my personal dev/Craft abilities and the budget is small for this project. Wonder if we forget the ability to show existing ones but somehow have a simple way to add them. A field with comma separated words maybe? – richardpixel Apr 28 at 16:35
  • I just looked into how Craft creates tags and it's a bit more advanced than just submitting the right data. They appear to create them dynamically and then just match their IDs in the submitted post request, so adding support for this as a front-end form field would be more involved and require some planning and a Custom Form Field. Our default Tag field will remain just a simple implementation that allows a user to choose an existing tag or tags. – Ben Parizek May 4 at 16:31
  • Alternatively, as you suggest, you could consider some other path like a comma separated list in a field. What makes the most sense will probably just depends how you need to be using the data being collected and what the budget allows. – Ben Parizek May 4 at 16:32

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.