Hi AEM Community,
I'm working on an AEM Forms implementation and need some guidance on the best approach for the following use case:
Requirements:
token parameter that needs to be capturedFlow:
Parent URL (with token) → iFrame loads AEM Form → Capture token → Backend API call → Prefill form fields
My Questions:
Has anyone implemented a similar pattern? What approach worked best for you?
Any guidance, code samples, or best practices would be greatly appreciated!
Thanks in advance!
Solved! Go to Solution.
Views
Replies
Total Likes
Hello @mancillaignAdobe
You can try the below :
You can :
- Use window.postMessage to securely send token from parent to iFrame.
// Parent page
const token = new URL(window.location.href).searchParams.get('token');
document.getElementById('aem-form-iframe').contentWindow
.postMessage({ token }, 'https://your-aem-domain.com');
// AEM Form (iFrame)
window.addEventListener('message', (event) => {
if (event.data.token) {
const token = event.data.token;
// Use token for API call
}
});
- Not expose external API or token client-side; send token to custom AEM servlet.
// iFrame JS (after receiving token)
fetch('/bin/userdata', {
method: 'POST',
body: JSON.stringify({ token }),
headers: { 'Content-Type': 'application/json' }
})
.then(r => r.json())
.then(data => {
// Prefill fields
document.getElementById('name').value = data.name;
document.getElementById('email').value = data.email;
});
- Implement Custom AEM Servlet to handle receiving token and fetching user data.
@SlingServlet(paths = "/bin/userdata", methods = "POST")
public class UserDataServlet extends SlingAllMethodsServlet {
protected void doPost(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws IOException {
String token = req.getParameter("token");
// Fetch user info from backend API using token
// Return JSON: {"name":"John Doe", "email":"john@example.com"}
}
}
- After receiving user data, set form field values via JS:
document.getElementById('name').value = data.name;
document.getElementById('email').value = data.email;
You can also prefill using OOTB Prefill Service.
https://experienceleague.adobe.com/en/docs/experience-manager-learn/forms/adaptive-forms/prefill-ser...
Hello @mancillaignAdobe
You can try the below :
You can :
- Use window.postMessage to securely send token from parent to iFrame.
// Parent page
const token = new URL(window.location.href).searchParams.get('token');
document.getElementById('aem-form-iframe').contentWindow
.postMessage({ token }, 'https://your-aem-domain.com');
// AEM Form (iFrame)
window.addEventListener('message', (event) => {
if (event.data.token) {
const token = event.data.token;
// Use token for API call
}
});
- Not expose external API or token client-side; send token to custom AEM servlet.
// iFrame JS (after receiving token)
fetch('/bin/userdata', {
method: 'POST',
body: JSON.stringify({ token }),
headers: { 'Content-Type': 'application/json' }
})
.then(r => r.json())
.then(data => {
// Prefill fields
document.getElementById('name').value = data.name;
document.getElementById('email').value = data.email;
});
- Implement Custom AEM Servlet to handle receiving token and fetching user data.
@SlingServlet(paths = "/bin/userdata", methods = "POST")
public class UserDataServlet extends SlingAllMethodsServlet {
protected void doPost(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws IOException {
String token = req.getParameter("token");
// Fetch user info from backend API using token
// Return JSON: {"name":"John Doe", "email":"john@example.com"}
}
}
- After receiving user data, set form field values via JS:
document.getElementById('name').value = data.name;
document.getElementById('email').value = data.email;
You can also prefill using OOTB Prefill Service.
https://experienceleague.adobe.com/en/docs/experience-manager-learn/forms/adaptive-forms/prefill-ser...
Views
Likes
Replies