Form Generator

The Form Generator plugin is not included with Gentics Mesh by default. In this article, you will learn how to configure this functionality.

Enable Form Generator plugin

The Form Generator feature is enabled by default in Gentics Portal | php, which proxies requests to the Form Generator Mesh Plugin. Public endpoints from http://<portal>/api/forms/(.*) will be passed to http://<mesh>/api/v1/<project-name>/plugins/forms/ and the portal’s route path will be removed from the request, also if a user is logged in the token will be passed with the request. Generally, these endpoints should be used from client-side scripts, so the Gentics Portal | php side configuration is automatically done this way.

Legacy Form Generator Plugin

The Form Generator feature is enabled by default in Gentics Portal | php, which proxies requests to the Form Generator Mesh Plugin. Public endpoints from http://<portal>/api/fg/(.*) will be passed to http://<mesh>/api/v1/<project-name>/plugins/fg/ and the portal’s route path will be removed from the request, also if a user is logged in the token will be passed with the request. Generally, these endpoints should be used from client-side scripts, so the Gentics Portal | php side configuration is automatically done this way.

Because the plugin is not included by default with Gentics Mesh, please contact our Team.

Render forms from views

Although the recommended way to display forms is client-side rendering, it is possible to render a form in views with the @renderForm helper:

@renderForm('<formUuid>')

To render an existing but not yet completely filled form you can pass the form cookie value as an option. The Form Generator feature loads the $COOKIE_NAME cookie (default: fg-data) into all views into the $fgCookie variable. This variable contains the cookie name ($fgCookie['key']) and the cookie value ($fgCookie['value']). The @renderForm helper supports passing options, like this cookie value:

With static variables:

@renderForm('<formUuid>', ['forms-data' => '<cookieValue>'])

With passed variables (assuming you have a formUuid field on your node):

@renderForm($node['fields']['formUuid'], [$fgCookie['key'] => $fgCookie['value']])

It is also possible to add the language for the form via the language variable: With static variables:

@renderForm('<formUuid>', ['forms-data' => '<cookieValue>', 'language' => 'de'])

New versions of the Mesh forms plugin support poll forms and adding a template context to customize rendering. The template context will be concatenated with the base template path configured in the plugin, and if a needed template is found in this path it is prioritized over generic templates. With static variables:

@renderForm('<formUuid>', ['templateContext' => 'customFormTheme'])

When rendering poll forms, the plugin will render the results, only if it determines that the user already participated in that poll. Rendering the results can also be forced by setting the showResults option:

Example:

@renderForm('<formUuid>', ['showResults' => true])

Disable caching for any page that uses renderForm (or fgRender) directive: Add 'renderForm' to portal.php config in cache.http.exceptions.

Example:

'cache' => [
        //[...]
        'http' => [
            //[...]
            'exceptions' => [
                'renderForm',
            ]
        ]
    ],
Legacy Form Generator Plugin

Although the recommended way to display forms is client-side rendering, it is possible to render a form in views with the @fgRender helper:

@fgRender('<formUuid>')

To render an existing but not yet completely filled form you can pass the form cookie value as an option. The Form Generator feature loads the $COOKIE_NAME cookie (default: fg-data) into all views into the $fgCookie variable. This variable contains the cookie name ($fgCookie['key']) and the cookie value ($fgCookie['value']). The @fgRender helper supports passing options, like this cookie value:

With static variables:

@fgRender('<formUuid>', ['fg-data' => '<cookieValue>'])

With passed variables (assuming you have a formUuid field on your node):

@fgRender($node['fields']['formUuid'], [$fgCookie['key'] => $fgCookie['value']])