Build Engaging Forms Using Core Components and Headless Adaptive Forms on AEM 6.5 Forms build-engaging-forms-using-core-components-and-headless
Lab Overview lab-overview
In this hands-on lab, you learn how to use AEM Forms with the latest Core Components—aligned with AEM Sites—to create adaptive forms quickly. Deliver these forms as headless experiences to web, mobile, and chat channels for seamless omnichannel data capture. You also learn best practices around styling, customizations, and front-end development.
Key takeaways key-takeaways
-
Business Agility: As a business user, I can author Form experience for multiple channels easily.
-
Power to frontend developer: As a frontend developer, I can control the end-user experience using headless forms.
-
Developer Velocity: As a developer, I can easily and consistently customize Sites and Forms components.
Before you start pre-requisites
To use this hands-on lab:
-
Install the latest release of Git. If you are new to Git, see Installing Git.
-
Install Node.js 16.13.0 or later.
-
Enable Headless Adaptive Forms in your AEM 6.5 Forms environment.
-
Install Microsoft Visual Studio Code or any plain text editor. Examples in this document make use of Microsoft Visual Studio Code.
Lesson 1 lesson-1
Objective lesson-1-objectives
Familiarize yourself with the AEM 6.5 Forms environment.
Lesson context lesson-1-context
In this lesson, you familiarize yourself with AEM 6.5 Forms by navigating the user interface.
Exercise lesson-1-excercise
-
Open your browser and enter the URL of the author environment. For example:
https://localhost:4502. -
After you are logged in, navigate to the AEM Forms UI. Click Forms.
{width="50%"}
-
Click Forms & Documents. Dismiss any pop-ups related to preferences or information.
{width="50%"}
All the available forms are displayed.
{width="50%"}
Lesson 2
Objective
Author an Adaptive Form using the latest Core Components, configure, and submit the form.
Lesson context
As a business user, you are going to use the Adaptive Forms editor and its out-of-the-box Core Components to build an Adaptive Form. You can then deliver the form to Web, mobile, and chat channels to capture data.
Exercise
-
Create a submission endpoint for the form:
-
Open https://pipedream.com/requestbin in a new browser tab.
{width="50%"}
-
Click Create a public bin and copy the endpoint URL.
{width="50%"}
This particular endpoint serves as an example for submitting and viewing data. In actual production, you use your own endpoint or data sources to store the captured data.
-
-
Author an Adaptive Form:
-
In the browser tab used in Lesson 1, navigate to the AEM Forms web interface and navigate to Forms > Forms and Documents.
-
Click Create and select Adaptive Form.
{width="50%"}
-
Select the Blank with Core Components template from the template selection screen as shown below and click Next.
{width="50%"}
-
Specify
Contact usas the Title of the form. Ensure that the Name of the form iscontact-us.
{width="50%"}
-
Click Create. A dialog box is displayed.
-
On the dialog box, click Edit. The form opens in the Adaptive Form editor. Dismiss any pop-ups or dialogs for preferences or information.
-
Open the Components browser and drag and drop the Panel component to the middle of the screen.
{width="50%"}
-
Drag and drop components from the Components browser to create a form, similar to the following:
{width="50%"}
-
Open the Content Browser, click the Guide Container properties icon, and open the Submission tab.
-
Select the Submit to REST endpoint Submit Action
-
Select the Enable POST request option, and specify the REST endpoint created in lesson 2 in the URL for POST request text box, then click the Done icon.
{width="50%"}
-
-
Publish an Adaptive Form:
-
Open AEM UI, navigate to Forms > Forms & Documents. Select the form created in the previous step and click
Publish. -
On the Publish Assets dialog box, click Publish. The success message is displayed.
-
Lesson 3
Objective
Update styles using frontend development best practices.
Lesson context
In this lesson, as a front-end developer, you learn how you can update styling for the previously created Adaptive Form easily.
Exercise
Set up a local repository of the theme:
-
Open the Command Prompt or shell with administrator rights:
{width="50%"}
-
On the Command Prompt, use the following command to navigate to
c:\gitfolder.code language-shell cd gitIf the folder does not exist, use the
md gitcommand to create it. -
Use the following command to clone the theme frontend code:
code language-shell git clone -b WKND https://github.com/adobe/aem-forms-theme-canvas -
Use the following command in the listed order to navigate to the aem-forms-theme-canvas directory and open Visual Studio Code.
code language-shell cd aem-forms-theme-canvas code . {width="50%"}
-
Select Trust the authors of all files in the parent folder and click Yes, I trust the authors.
{width="50%"}
-
Rename the
env_templatefile to .env. To rename the file, right click the env_template file and select the Rename option. {width="30%"}
{width="50%"}
-
Set the following values for the variables in the .env file and save the file:
-
AEM_URL: Specify the URL of a publish instance. For example,
https://localhost:4502/ -
AEM_ADAPTIVE_FORM: Specify the name of the form. For example,
contact-us.
-
-
In the Command Prompt window, run the following command:
code language-shell npm install
note note NOTE - If you get a message asking to update
npmthrough thenpm notice Run npm nstall -g npm@9.6.0command, ignore the message. - Unless you are instructed in the workbook, do not run other
npmcommands.
- If you get a message asking to update
-
Now, run the following command to preview the form.
code language-shell npm run live
Once the above command is executed, wait for the
webpack compiledmessage. The form is displayed in a browser tab.note note NOTE If you experience a blank screen in browser after executing the npm run livecommand for more than 3-4 minutes, changelocalhostin browser URL to 127.0.0.1 and hit Enter. {width="50%"}
-
In Visual Studio Code, open the
PROJECT\src\site\_variables.scssfile. Notice the$errorcolor is a shade of RED. {width="50%"}
-
In the browser, submit the form to see the Red color in the First Name field.
-
Set the $error color to #5736eb and save the file.
-
Refresh the browser and submit the form. Notice that the error color on the first name field has changed accordingly.
-
In the Command Prompt, press CTRL+C, enter Y, and press the Enter key to terminate the npm process. It is important to stop the npm server so it does not conflict with the next set of exercises.
-
Close Visual Studio Code and Command Prompt windows.
Lesson 4
Objective
Render the form to Web/mobile and other interfaces as a headless form.
Lesson context
In this lesson, as a frontend developer, you learn how you can render the Adaptive Form created previously as a headless form using a React spectrum design framework.
Exercise
Set up a local repository using the React starter project:
-
Open the Command Prompt using administrator rights.
{width="30%"}
-
On the Command Prompt, use the following command to navigate to
c:\gitfolder.code language-shell cd git -
Use the following command to clone the Adaptive Form react starter project:
code language-shell git clone https://github.com/adobe/react-starter-kit-aem-headless-forms
-
Use the following commands in the listed order to navigate to the react-starter-kit-aem-headless-forms directory and open Visual Studio Code.
code language-shell cd react-starter-kit-aem-headless-forms code .
The Visual Studio Code window opens.
{width="50%"}
To render the form hosted on your publish environment:
-
Rename the env_template file to the .env file. To rename, right-click the env_template file and select the Rename option.
{width="30%"}
-
Set the following values for the variables in the .env file. After updating the variables, save the file.
-
AEM_URL: Specify the URL of the publish environment. For example,
https://localhost:4503/ -
AEM_FORM_PATH: Specify the path of the Adaptive Form created in the previous lesson. For example,
/content/forms/af/contact-us/
-
-
Open the command window, ensure you are at the react-starter-kit-aem-headless-forms directory, and run the following command:
code language-shell npm install
-
In the Command Prompt window, run the following command:
code language-shell npm start
The above command starts a local development server which would render the form definition fetched from AEM in a headless way using the react-spectrum frontend library.
note note NOTE If you experience a blank screen in browser after executing the npm startcommand for more than 3-4 minutes, changelocalhostin browser URL to 127.0.0.1 and hit Enter.
Let’s make changes on the form on the server as a business user and view changes reflected in the headless form automatically.
-
Open the AEM Forms management interface in the browser. For example, http://localhost:4502/aem/forms.html/content/dam/formsanddocuments.
-
Select the Contact Us form and click Edit. It opens the form in the Adaptive Forms editor.
-
Select the Contact number field and click the Edit icon (Pencil icon) in the toolbar. If you are not able to see the pop-up toolbar, switch to Edit mode. Click the Edit button in top right, left of the Preview button.
{width="50%"}
-
Change the label to Mobile Number. Click any empty space in the form and the changes made to the form are saved.
Let’s publish the updated form to propagate the changes to the published environment.
-
In the AEM Forms management interface tab, select the contact us form, and click Unpublish. If you do not see the Unpublish button, skip to step 3 to publish the changes directly.
-
Click Unpublish. Click Close in the respective dialog.
-
After the browser refreshes, select the contact us form and click Publish.
-
Click Publish. Click Close in the respective dialog.
-
Refresh the browser tab with the headless form displayed. Notice, the Contact Number label has changed to Mobile number.
-
Open the Command Prompt window that is used to start the react-starter-kit-aem-headless-forms project, press CTRL+C, then
enter Y and press Enter key to terminate the npm process. It is important to stop the npm server so it does not conflict with the next set of exercises. -
Close Visual Studio Code and Command Prompt windows.
Lesson 5
Objective
Render the form as a headless form using Google Material UI
Lesson context
In this lesson, as a front-end developer, you learn how to render the Adaptive Form created previously as a headless form using Google Material UI.
Exercise
Set up a local repository using the Material UI starter project:
-
Open the Command Prompt using administrator rights.
{width="30%"}
-
On the Command Prompt, use the following command to navigate to
c:\gitfolder.code language-shell cd git -
Run the following commands in the listed order to create a folder named
muiand navigate to themuifolder using following commands:code language-shell mkdir mui cd mui -
Use the following command to clone the Adaptive Form react starter project:
code language-shell git clone -b mui-lab https://github.com/adobe/react-starter-kit-aem-headless-forms
-
Use the following command in the listed order to navigate to the react-starter-kit-aem-headless-forms folder and open the code in Visual Studio Code:
code language-shell cd react-starter-kit-aem-headless-forms code .
To render the form hosted on your publish environment:
-
Rename the env_template file to the .env file. To rename, right-click the env_template file and select Rename.
{width="30%"}
-
Set the following values for the variables in the .env file. After updating the variables, save the file. Use the CTRL + S switch combination to save the file.
-
AEM_URL: Specify the URL of the publish environment. For example, https://localhost:4503
-
AEM_FORM_PATH: Specify the path of the Adaptive Form created in the previous lesson. For example, /content/forms/af/contact-us/
-
-
Open the command window, ensure you are at the react-starter-kit-aem-headless-forms directory, and run the following command:
code language-shell npm install
-
In the Command Prompt window, run the following command:
code language-shell npm start
The command starts a local development server and renders the form definition fetched from AEM in a headless way using the Google Material UI frontend library.
note note NOTE If you experience a blank screen in browser after executing the npm startcommand for more than 3-4 minutes, changelocalhostin browser URL to 127.0.0.1 and hit Enter.
Lesson 6
Objective
Create an alternate look and feel of the headless form using Material UI component variations
Lesson context
As a front-end developer, you are going to learn how to build alternate Material UI versions of various components in this lesson. You are also going to apply them to the Adaptive Form the business user created earlier.
Exercise
Update the variation of components in the headless project. To change the variant of the material UI text input component to OutlinedInput:
-
In Visual Code, navigate to the text input component by opening the
index.tsxfile atsrc/components/textinput/index.tsx. -
Add
//at the beginning of the code line 104. It converts the line to a comment.code language-shell //const Cmp = \'outlined\' === appliedCssClassNames ? OutlinedInput: Input; -
Add the following at line 105 to use a different variant of the component and save the file. Use the CTRL + S switch combination to save the file.
code language-shell const Cmp = OutlinedInput;
It is essential to use correct capitalization for the ‘OutlinedInput’ variant else the compilation would fail. The local development environment compilation begins automatically in Command Prompt. Wait until you see the following message
webpack 5.75.0 compiled with 3 warnings in 6659 msinside proxy reqsetting new origin header -
Refresh the browser, if it does not refresh automatically, to see the text input component use a different variant.
{width="50%"}
This change happens for end users without any change to form definition at AEM Forms Server and is specific for the headless
channel under consideration. For example, a web channel in this lab.
-
Close Visual Studio Code and Command Prompt windows.
Frequently Asked Questions (FAQs)
Next steps
You now know how to build adaptive forms and deliver them across channels with headless forms. Use those skills to create scalable, high-quality data-capture experiences wherever your users are.