Documentation

Using Fragments to Build Forms

Available Liferay 7.4 U45+/GA45+

Liferay includes form fragments for building object forms in content pages. To build a form, add a form container to a content page or page template and map it to a published object. The container automatically populates fragments mapped to each object field. You can organize, remove, or add fragments manually. Once published, end users can create object entries using the form.

To build forms in content pages, you must

  • Place form fragments only in a mapped form container.

  • Map every form fragment in the form to an object field to prevent data loss.

  • Include fragments in the form container for all mandatory object fields.

  • Make mandatory form fragments visible.

  • Include a visible submit button in the form container.

By default, Liferay includes the Form Components fragment set, but you can create your own. See Creating Form Fragments for more information.

Important

Form fragments can only be used with custom objects. Therefore, Liferay hides the Form Components fragment set until you have at least one published object. Once published, users with access to the object can view and use the Form Components fragments. See Creating Objects for more information.

Creating a Form

  1. Begin editing a content page or page template.

    Display page templates do not support form fragments.

  2. (Optional) Design a layout using fragments. See Building Responsive Layouts with Fragments for more information.

  3. Add the Form Container fragment to the page and map it to an object.

    The container automatically generates a Submit button and fragments for all object fields. They appear in alphabetical order. Mandatory fields are marked accordingly.

    Add the form container and map it to an object.

  4. Remove non-mandatory fields that you don’t want in the form.

  5. Drag and drop form fragments to reorganize them. By default, form elements are organized alphabetically.

  6. (Optional) Add basic fragments to the form container. You can use basic components (e.g., grids, separators, paragraphs, images) to provide structure and style to your form container.

    Add basic fragments to the form container and reorganize your page elements to create the desired structure.

  7. Configure the fragments. Form fragments include both standard and unique configuration options.

    Note

    Form fragment configuration options become available after mapping the fragment to an object field.

    Configure the form fragments.

  8. Click Publish when finished.

Supported Field Types for Fragment Components

Each form fragment can support one or more form field types, which correspond to object field types.

The default form components support these fields.

Fragment

Form Field Types

Object Field Types

CAPTCHA

N/A

N/A

Checkbox

Boolean

Boolean

Date

Date

Date

File Upload

File

Attachment

Numeric Input

Number

Integer, Long Integer, Decimal, Precision Decimal

Select from List

Relationship, Select

Relationship, Picklist

Submit Button

N/A

N/A

Text Input

Text

Text, Long Text, Rich Text

Additional Information