Can't pre-fill form fields with procedure described in Mautic documentation

Thank you all for the suggestions and support.

@leoschuler I checked the Javascript Console and I did see an error. It says…“Uncaught SyntaxError: Unexpected identifier (at ?tve_name=Terry&”

When I clicked the error it took me to this line of code…
“var __fields = decodeURIComponent(”&")_"

So what would be causing a syntax error in this code?

I didn’t see anything unusual in the network tab.

@robm Yes the form data from thrive leads is showing up in the URL of the thank you page it’s just not populating in the mautic form.

I also double checked the attribute field HTML name in the mautic form and it matches the variable details in the thrive leads form.

@joeyk Yes, I believe the fields are publicly updateable.

Ok I figured out the problem.

It was a syntax error as suggested in the console. I copied Robins code on his website and it looks like there was an underscore “_” after .split(”&").

I deleted this underscore and it now works.

@robm I would update this on your website to save others the frustration of troubleshooting! Thank you very much for the tutorial, it was very easy to follow step by step and I’m very excited to finally get thrive leads working with Mautic now.

@leoschuler Thank you for pointing me in the right direction on where to look!

1 Like

Great catch, no idea how the xtra “_” got there as this would have been a cut paste. Nonetheless I have edited the blog.

Glad it is now working

I checked the post (it has the old version yet, perhaps its cache) the underscore from the first line suppose to be the first char of the second line the name of the variable is __field (with double underscore) and the second line had only one underscore, I am pasting the code again with an additional “;” at the end of the lines, that way it is possible to " minimize " the code by suppressing new lines

var __fields = decodeURIComponent("&");

__fields.forEach( param=> {
  const [fieldName, fieldValue ] = param.split("=");  
  const el = document.querySelector(`form *[name="mauticform[${fieldName}]"]`);
  if( !!el ) el.value = fieldValue;
1 Like

We created this PR that should help with prefilling. Especially useful if you use Mautic with an external Website/CMS such as WordPress.

Please contribute by testing: Fix issue with pre-populating the value of a form field from the URL query parameters by volha-pivavarchyk · Pull Request #11077 · mautic/mautic · GitHub