1

We're in the process of scoping out an online assessment form to be build in Craft CMS. We need to give the client the ability to add, edit and remove questions (custom fields) and would ideally like to handle all entries through a channel, rather than a dedicated form plugin. The thing I'm struggling with at the moment is how to render the field layout for a channel in my template. Expression Engine handles this using the {custom_fields} loop.

Is there an equivalent template tag for Craft CMS? Or would we be better of working with Freeform or SproutForms?

Any help would be much appreciated. Thanks.

1

Personally I don't have any experience with Free Form but have been using Sprout forms for quite some time now.

In Sprout forms your client can create entire forms or just add a couple of fields however you like it. The support on Sprout forms is decent aswell.

Plus sprout forms got email notifications aswell which might be interesting for your client.

  • Thanks Justin. Sounds good. Do you know if it's possible to create a list of entries submitted by a user? Users will need to log in to submit an assessment. They'll need to be able to submit multiple assessments and be able to view past entries. This was why I'd been exploring the native entry form route, as I know that'll be doable with standard twig tags. – GazCrane Nov 29 '18 at 14:46
  • That is indeed possible although I haven't tried it personally with Sprout forms. I made something similar a while back in Craft 2 just with native craft so it should be possible to do so in 3. Where Sprout forms could be a good addition is by giving your client the oppertunity to create their own forms and just save them as an entry by user. – Justin Dekkers Nov 29 '18 at 15:23
1

Yes, you can do this without a plugin. You just need a frontend entry form, ala https://docs.craftcms.com/v3/dev/examples/entry-form.html

Now if you want them to be able to add/remove fields, then instead of hardcoding the fields, you'll need to iterate through the fields that are in a particular field layout.

A way to do that is discussed here: How to display all fields belonging to current entry?

  • Thank Andrew. I did look at the solution you've linked to yesterday but it kept throwing errors: Calling unknown method: craft\elements\db\EntryQuery::getFieldLayout() Calling unknown method: craft\elements\db\EntryQuery::getFields() Those can definitely be used in front-end templates? – GazCrane Nov 29 '18 at 15:02
  • Yeah that example is for Craft 2; you'll need to adapt it for Craft 3. You can try something like {% set fields = craft.app.fields.getFieldsByLayoutId(123) %} {% for field in fields %} {% endfor %} -- swap in the layout id in question for the 123 – andrew.welch Nov 29 '18 at 15:19
  • Cool. Thanks Andrew. The template's no longer throwing errors, but not actually rendering any content. However I think I'm on the right path now, so will do some more experimenting. May also take Sprout Forms for a spin. – GazCrane Nov 29 '18 at 17:04

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.