Fill external forms 2.0 using javascript?

Anonymous
Not applicable

Fill external forms 2.0 using javascript?

Hi there,

We have external pages in which we embed some of the Forms 2.0 JavaScript.

We would like to populate some hidden fields based on some server side code/data.

Can this be done? Perhaps using JavaScript? Any examples?

Thanks

Tags (3)
2 REPLIES 2
Josh_Hill13
Level 10 - Champion Alumni

Re: Fill external forms 2.0 using javascript?

Probably with javascript and jquery. Consult developers.marketo.com and/or get a dev.

SanfordWhiteman
Level 10 - Community Moderator

Re: Fill external forms 2.0 using javascript?

We would like to populate some hidden fields based on some server side code/data.

Can this be done? Perhaps using JavaScript? Any examples?

Under the hood, Marketo forms are HTML forms equipped with a very handy JS API that lets you insert custom code and data at the right place and time.

Thus, any recipe that allows you to fetch data via JSON/XML (or even via variables "stamped" into the page on your server, with no additional HTTP calls) can be easily extended to insert the fetched values into hidden fields.

The real questions are what server you're fetching from and what format it uses when sending back data.  If the server you're fetching additional data from is the same webserver that hosts your embedded form, this makes things easier because you don't have to build in cross-domain compatibility (Jeff Coveney​ take note!).  But even across domains -- for example, your page at https://www.example.com is hosting a form from //pages.example2.com and bringing in hidden fields from //webservice.example3.com -- a skilled dev can make it all work.