to give you context, im using the javascript embed code to show a formstack form on my webpage, and i have a code where i check if we have in local storage variables the name and email of the user or if in the url link we have those parameters, if we find those value then we storage on a constant and then we add those values to prefill the first name, last name and email
I’m using the function FF_OnAfterRender()
to insert those values after the form is ready and it does but the problem is that as soon as i click on the field is like the value is delete or even if i submit the form because those fields are required it says that they’re empty
I use add the value using DOMContentLoaded
, also the FF_OnBeforeRender()
but the result is the same, this is the code that i have right now
const urlParams = new URLSearchParams(window.location.search);
// Get the values from the URL parameters
const email = urlParams.get('email') || localStorage.getItem('email');
const firstName = urlParams.get('first_name') || localStorage.getItem('firstName');
const lastName = urlParams.get('last_name') || localStorage.getItem('lastName');
// Check if any required field is missing
if (!email || !firstName || !lastName) {
// Redirect to another URL if any required field is missing
window.location.href = 'https://coalitionforgreencapital.com/ggrf-investment-prioritization/';
}
function FF_OnAfterRender() {
document.getElementById('field166065253').value = email;
document.getElementById('field166065639').value = lastName;
document.getElementById('field166065638').value = firstName;
return true
}
FF_OnAfterRender();
I test the code on another form (not a formstack one) and the code works fine, so i’m a little lost on how should i’ve to handling this, i take as example Top Javascript Fixes / Recipes
I’m using this form on a wordpress site that is using elementor btw