Creating Forms Using Form Fragments
Use form fragments to create and manage forms on content pages or page templates. With form fragments, you can map fields to objects, organize layouts, and configure form settings. You can also handle object relationships, manage related data, and customize form elements to suit your site’s requirements.
Creating a Form
-
Ensure a custom object is created before you start.
-
Begin editing a content page or page template.
-
(Optional) Design a layout using fragments. See Building Responsive Layouts with Fragments for more information.
-
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.
Liferay DXP 2024.Q3+/Portal 7.4 GA125+ In the pop-up, select the fields and related fields to display in the form. See Handling Object Relationships Within Form Container Fragments to learn more about managing related fields in form fragments.
-
Remove non-mandatory fields that you don’t want in the form.
Liferay DXP 2024.Q3+/Portal 7.4 GA125+ To manage available and related fields, select the Form Container fragment and click Manage Form Fields in the General tab on the right under Content Type.
-
Drag and drop form fragments to reorganize them. By default, form elements are organized alphabetically.
-
(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.
-
Configure the fragments. Form fragments include both standard and unique configuration options.
NoteForm fragment configuration options become available after mapping the fragment to an object field.
-
Beta Feature (Optional) If draft mode is enabled for the object, configure the Submitted Entry Status for the form’s submit button: Approved or Draft.
ImportantWhen using form fragments to update entries in a display page, you cannot change an entry’s status from approved to draft.
-
Click Publish when finished.
Handling Object Relationships Within Form Container Fragments
Liferay DXP 2024.Q3+/Portal 7.4 GA125+
Manage relationships between objects and handle related data directly from Form Container fragments in content pages or display page templates.
To manage object relationships within form fragments,
-
Create a content page or a display page template.
-
Once you select an object in a Form Container fragment, a window opens displaying available fields, including related fields, as selectable options. Select one or more fields and click Save to populate the form.
In this example, the Employee Profile and Car objects have a one-to-many relationship, where each employee can be associated with multiple cars. When generating the form, you can select and combine fields from both objects to capture all the necessary information.
TipYou can also create multi-step applications where users can navigate through different steps, such as entering employee details, assigning a car, and confirming the entries.
-
After selecting the fields, manage them by clicking the Form Container fragment and using the Manage Form Fields button located in the General tab on the right under Content Type.
-
Alternatively, select a text or picklist field and set the Source and Field options on the right to manage those fields manually.