eZ Community » Learn » eZ Publish » Create a feedback form in eZ Publish...

Create a feedback form in eZ Publish 5 using ezforms-bundle

Monday 12 May 2014 3:33:49 pm

  • Currently 3 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Map your content to your form

We now only have to connect the dots: we have a Feedback eZ Publish content which eZFormsBundle's controller is in charge of handling. Additionally, we created an acme_feedback form type. So how can we tell eZFormsBundle to create a form of this particular type when handling that particular content?

eZFormsBundle's controller delegates form creation to a FormProvider service. There is no out of the box provider as form creation logic is prone to change across projects. Fortunately, the bundle provides all the tools necessary to easily create a provider service mapping content remote ids to form types.

Our service will instantiate the Heliopsis\eZFormsBundle\Provider\Form\ContentRemoteIdMap class and map the acme_feedback form type to our content's remote id (remember, the random string we saw in the administration interface after creating our content):

 

Please remember to use your own content remote id

A few notes:

  • If you're wondering what is the @form.factory service, it is a Symfony service used to instantiate forms, it is required as constructor argument by the Heliopsis\eZFormsBundle\Provider\Form\ContentRemoteIdMapclass.
  • The %heliopsis_ezforms.form_provider.content_remoteid_map.class% parameter is defined in eZFormsBundle's configuration and links to Heliopsis\eZFormsBundle\Provider\Form\ContentRemoteIdMap

NB: You may also be wondering why we don't use the content or location id instead of this insanely long remote id. The reason to map to a content instead of a location is because that way you'll be able to use your form on multiple locations without having to update your ezpublish configuration. As for the id vs remote id, regular ids being autoincremented values, they may vary between your staging and production environments while the remote id is intended to be used as an immutable reference accross environments. By the way, eZPublish's public API allows you to specify arbitrary (thus more meaningful) strings as remoteIds when creating content, but that's beyond the scope of this tutorial

Finally, we must tell eZFormsBundle to use our form provider service. We can add the following lines to our application's config.yml:

 

If everything went well, you should now be able to display your form when navigating to your Feedback content at http://ezforms-tutorial.localhost/ezdemo_site/Feedback. Submitting the form should also redirect you to the confirm view and display your confirmation message.

Well done! But there are a couple things still missing...

 

 

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)

Proudly Developed with from