Render Sitecore Experience Forms Using Sitecore XP 10.4 with a Headless Approach (Next.js + JSS SDK)
In this blog post, we’ll walk through rendering Sitecore Experience Forms using Sitecore XP 10.4 (Update 1) with a headless (Sitecore-first) approach, leveraging Next.js and Sitecore JSS SDK. This guide assumes you're using connected mode, where your frontend directly interacts with your Sitecore backend.
Goal: Enable a fully functional Sitecore Experience Form to render and work within a headless Next.js application.
đ§ą Prerequisites
Before getting started, ensure you have the following:
Backend:
-
✅ Sitecore XP 10.4 Update-1 installed
-
✅ Sitecore Headless Rendering 22.0.0 package installed
Frontend:
-
✅ Node.js and npm installed
-
✅ Visual Studio Code (or any preferred IDE)
đ§ Step 1: Set Up Sitecore for Headless Forms
Since this is a Sitecore-first approach, we begin by configuring everything in Sitecore before moving to Next.js.
đ 1. Create an API Key
-
Go to Sitecore Content Editor
-
Create a new API Key item (e.g., under
/sitecore/system/Modules/Layout Service/API Keys) -
Note down the Item ID — this will be your API Key used in the frontend.
đ§ą 2. Create a JSON Layout
-
Create a Layout item using the appropriate JSON rendering template.
-
This layout will be responsible for exposing your page and component structure via the Layout Service.
đ 3. Add a Placeholder (jss-main)
-
Add a placeholder called
jss-mainto the layout. -
In the Allowed Controls field, define which components can be rendered inside it (e.g., your custom form component).
đ§Š 4. Create a Form Component Rendering
-
Add a new rendering item for your form component.
-
Important:
-
Set Rendering Contents Resolver to Sitecore Forms Resolver.
-
Ensure the Component Name exactly matches the name you’ll use in the Next.js component (e.g.,
Quizform).
đ 5. Link Placeholder to Layout Service
-
Revisit your layout item.
-
Under Layout Service Placeholders, add the
jss-mainplaceholder.
đ 6. Create the Experience Form
-
Go to Forms in the Sitecore dashboard.
-
Create a new form (e.g., “Quiz Form”) — this will serve as the data source.
đ 7. Configure the Page Item
-
Go to the page item where you want to render the form.
-
Assign the layout you created.
-
Insert the form component and link it to the form data source.
đ 8. Set Up a Plain HTTP Binding in IIS
To avoid SSL and CORS issues when using self-signed certificates:
-
Create a new IIS binding for your Sitecore site using HTTP.
-
Add the host entry to your
hostsfile (e.g.,127.0.0.1 mysitecore.local).
đť Step 2: Create the Next.js Frontend App
With Sitecore set up, now let’s create and configure your frontend using Next.js and Sitecore JSS.
đ️ 1. Generate the Next.js JSS App
In your terminal:
-
Select Next.js with SSR
-
When prompted:
-
Enter the Sitecore host with HTTP (e.g.,
http://mysitecore.local)
⚙️ 2. Set Up the App
Run:
-
Provide your Sitecore host and API key
đŚ 3. Deploy Configuration
-
This deploys config files like component definitions to Sitecore.
đ ️ 4. Scaffold the Form Component
This creates a new React component. Replace the generated content with the following Sitecore-recommended code:
đ 5. Update .env and scjssconfig.json
Update your environment variables
-
JSS_EDITING_SECRET(Update the
JSS_EDITING_SECRETkey in the.envfile with the value of thedeploySecretkey from thescjssconfig.jsonfile.) -
SITECORE_API_KEY(As per your environment item of the api key created in sitecore instance in previous setsp)
-
SITECORE_SITE_NAME( this value you can fetch from the name attribute of the site tag present inside jss-quix-demo.config file folder of the next js project)
GRAPH_QL_ENDPOINT(/sitecore/api/graph/edge)
SITECORE_API_HOST(Sitecore host name HTTP version ,the new binding created in IIS)
đ 6. Modify next.config.js
Update rewrites to route API calls to Sitecore:
đ Step 3: Run the App in Connected Mode
Start the project:
Then visit:
đ http://localhost:3000
You should see your Sitecore Experience Form rendered on the page, fully functional. On submission, the form data will be stored in the Sitecore database — just like it would in a traditional Sitecore-rendered site.
✅ Conclusion
Congratulations! You've successfully rendered a Sitecore Experience Form in a headless Next.js app using Sitecore-first configuration.
đ Recap:
| Step | Task |
|---|---|
| 1 | Configure Sitecore (layouts, placeholders, form component) |
| 2 | Scaffold the frontend with JSS CLI |
| 3 | Deploy config and set up the form component |
| 4 | Run in connected mode and test form submission |
đĄ You now have a flexible, scalable setup that can leverage Sitecore forms with modern headless frontend capabilities.
Comments
Post a Comment