Configure Forms fields as hidden in the Advanced configuration tab.
There’s a hidden field in this form. It holds the Site’s ID number, so that it can be passed to a data provider as an input value:
To follow the example you must first enable local network access in the Data Provider System Settings entry. See Enabling Access to Data on the Local Network for more information.
This example requires creating two data providers, and a form with four fields and three form rules. The table below contains a summary of the elements:
To configure this example,
-
Configure a data provider with these settings:
-
Name: Get Group Users
-
URL: http://localhost:8080/api/jsonws/user/get-group-users/group-id/
The
groupId
is passed as an input parameter to the data provider. In this example a hidden form field will be used to provide the group ID. -
User Name: test@liferay.com (or your administrator’s email address)
-
Password: [Enter the user’s password]
-
INPUTS:
- Label: Group ID
- Parameter: groupId
- Type: Number
-
OUTPUTS:
- Label: Email Address
- Path: $..emailAddress
- Type: List
Save the data provider.
-
-
Configure another data provider with these settings:
-
Name: Get User by Email
-
URL: http://localhost:8080/api/jsonws/user/get-user-by-email-address/company-id/20099/email-address/
You must retrieve your Liferay Instance’s ID (e.g., 20099). It’s the Instance ID displayed in Control Panel → Virtual Instances.
-
User Name: test@liferay.com (or your administrator’s email address)
-
Password: [Enter the user’s password]
-
INPUTS:
- Label: Email Address
- Parameter: emailAddress
- Type: Text
-
OUTPUTS:
- Label: First Name
- Path: $.firstName
- Type: Text
Add another output by clicking the plus symbol.
- OUTPUTS:
- Label: Last Name
- Path: $.lastName
- Type: Text
Save the data provider.
-
-
Create a new form and add these fields:
- Numeric field: Hidden Group ID
-
Predefined Value: [Site ID, e.g. 20123]
Find the Site ID in Site Settings → Site Configuration
-
- Select from List field: Who are You?
- Create List: From Autofill
- Text field: First Name
- Text field: Last Name
Give the form a title and save it.
- Numeric field: Hidden Group ID
-
Go to the Rules tab in the form and create a rule to autofill the Who are You? field’s list of options:
- CONDITION:
- If Hidden Group ID
Is Not Empty
- If Hidden Group ID
- ACTION:
- Do
Autofill
From Data Provider Get Group Users- Data Provider’s Input:
groupId
→ Hidden Group ID - Data Provider’s Output:
Email Address
→ Who are You?
- Data Provider’s Input:
- Do
Save the rule.
- CONDITION:
-
Go to the Rules tab in the form and create a rule to autofill the Who are You? field’s list of options:
- CONDITION:
- If Who are You?
Is Not Empty
- If Who are You?
- ACTION:
- Do
Autofill
From Data Provider Get User by Email- Data Provider’s Input:
emailAddress
→ Who are You? - Data Provider’s Output:
First Name
→ First Name - Data Provider’s Output:
Last Name
→ Last Name
- Data Provider’s Input:
- Do
Save the rule.
- CONDITION:
-
Go to the Rules tab in the form and create a rule to only enable the name fields if an email address hasn’t been selected:
- CONDITION:
- If Who are You?
Is Empty
- If Who are You?
- ACTION:
- Do
Enable
First Name - Do
Enable
Last Name
- Do
Save the rule.
- CONDITION:
-
Save and publish the form. Saving the rules did not save the form so you must go back to the Form tab and click Save, and Publish if the form is not already published.
To test the form, go to its dedicated URL and select an email address. Note the following behavior:
- Use the Who are you? field to choose your email address from a list of Users that belong to the current Site. This list is populated by a data provider calling the JSON web service get-group-users.
- Choosing an email address from the selector autofills the First Name and Last Name fields, and disables these fields so they cannot be edited.
- Leaving the Who are you? field blank (e.g., Choose an Option is displayed) enables both name fields so the user can input data directly.