Including form-builder forms in portlet

Enonic version: 4.10.x
OS: OSX

Hi,

I am trying to create a portlet that can include a form. I was hoping to use the form builder to create these forms.

We are already using the form builder to create forms - but they are all on their own pages (which I guess is what is the main usecase). What I want is to create a portlet that can include a related content of type form or something similar.

Is this something I need to implement from scratch via my own content type etc, or can I set up my portlet to somehow include a form created by a formbuilder? I have a vague idea of seeing this done somewhere else, but I’m not sure.

Hope to hear back from you soon!

Best regards,

Kristofer Selbekk

You should be able accomplish this, but it may require a bit of setup.

The formbuilder content (i.e. submitted form data from users) is dependent upon the form config data on the menu item where it was created. This is easily shown if you create a couple of form submissions, and later change some of the fields in the form config on the original menuitem. The submitted content then gets confused regarding what inputs the submitted data originally belonged to.

Hence:

What I want is to create a portlet that can include a related content of type form or something similar. Is this something I need to implement from scratch via my own content type

The formbuilder form config must come from the data on a menu item, not from a content. You could of course go the long route and design a custom contenttype with a lot of custom logic to create forms, but then you wouldn’t be using the Enonic formbuilder anymore! In other words, you need to create a modified version of the formbuilder datasource that gets the data from a remote menuitem. Tip: you can use the Java.el function getPageKeyByPath() to get the correct menuItemKey. The formbuilder portlet stylesheet should hopefully not need any significant changes, except if there are specific references to the current menuitem (you want to retrieve that data from a remote menuitem instead).

I’ve actually never seen this implemented anywhere, although I’ve discussed this kind of setup with a few of our clients. In the end, they all ended up using custom forms instead of using formbuilder. But this method should work.

Hi,

thanks for your reply. It’s not a huge deal for me to use the formbuilder - in fact, as long as I can save responses in Enonic in some way, I would actually prefer to implement my own form logic instead of using the formbuilder. I don’t want to change the way the formbuilder works, because we use this for other kinds of forms.

Let’s say I create my own custom form portlet and content type. How do I save responses via AJAX to the content repository?

Hi,

You can choose from these two functions in Enonic:
https://enonic.com/docs/4.7/content-service.html

And this:
https://enonic.com/docs/4.7/content-sendmail-service.html

Depending on if you want to send an e-mail as well or only store the data.

Beautiful :slight_smile: Thanks so much for your help!

Or create your very own Java controller…

BTW This is sooo much easier, flexible an fun to do in enonic xp :slight_smile:

1 Like

Hehe yeah I bet. We’re starting a new project with XP in a month or so, can’t wait to try it out :smile:

1 Like