Quantcast
Channel: WordPress.org Forums » [Royal Elementor Addons and Templates] Support
Viewing all articles
Browse latest Browse all 570

Need help with Popup Feature + Prefilling a form.

$
0
0

Replies: 0

Hey all. I’m having issues with having a form prefill information.

I have JSON script attached to the embed for a registration form that is supposed to record the URL of the page so that we can track who referred the registration.

The problem I’m encountering is that with my Pop-up set to Trigger on Page Load, the form doesn’t populate the text field when the page loads.

BUT it does work when any of the registration buttons on the page are clicked.

This is the exact code I’m working with :

<script src="https://www.cognitoforms.com/f/seamless.js" data-key="ptz7FzthWE-46op1ombSrA" data-form="5"></script>
<script>
Cognito.prefill({"RegistrationURL": window.location.href});
</script>

I’ve tried embedding code onto the page that the pop-up appears on. The code listens for the form to load and then tries to prefill it, but it’s been to no avail.

<script>
function prefillCognitoForm() {
if (typeof Cognito !== "undefined") {
Cognito.then(function() {
Cognito.prefill({"RegistrationURL": window.location.href});
});
}
}

window.addEventListener("load", function() {

setTimeout(prefillCognitoForm, 1000);


var observer = new MutationObserver(function(mutations, obs) {
var formElement = document.querySelector('.cog-cognito');
if (formElement) {
prefillCognitoForm();
obs.disconnect();
}
});
observer.observe(document.body, { childList: true, subtree: true });
});
</script>

Does anyone know the code that calls the pop-up in the first place? I want to try to tie the prefill script to the script that calls the pop-up.

– I’ve currently set the form field to visible (It’s the textbox that has no title) so that you can see what’s happening.

If anyone has any advice, or even just the snippet that calls the pop-up when it’s set to Page Load I’d appreciate it greatly!


Viewing all articles
Browse latest Browse all 570

Trending Articles