Using Javascript to Auto-Submit a form

Neil_Robertson6
Level 5

Using Javascript to Auto-Submit a form

Hi All,

Has anyone successfully managed to utilise Javascript to auto-submit a Marketo form?    I have manage to successfully address a form in the system using a simple document.forms['mktoForm_XXXX'].submit(); however the form itself never submits/redirect?

Thanks

N
Tags (1)
9 REPLIES 9
Rafael_Santoni1
Level 5

Re: Using Javascript to Auto-Submit a form

Yes. It is possible. I developed a solution here at Citrix that auto-submits a hidden form if the user is a return/cookied user.

I used jQuery using:
Mkto.formSubmit($jQ('#mktFrmSubmit').parents('form:first').get(0));

I do a lot more than just submit the form but that's the one-liner I am using to submit it.

The other thing to keep in mind is that I did this using the Forms 1.0 editor not 2.0, but my guess is that it should be possible with 2.0 as well perhaps with a minor change.

Good luck!

Rafael
Anonymous
Not applicable

Re: Using Javascript to Auto-Submit a form

Rafael:

Can you tell me where to insert the js in the for so it can be auto submitted?

Mkto.formSubmit($jQ('#mktFrmSubmit').parents('form:first').get(0));

Thank You

Jerry Cooper

thetrustadvisor@gmail.com

(310) 745-9942

SanfordWhiteman
Level 10 - Community Moderator

Re: Using Javascript to Auto-Submit a form

Not sure about the Marked as Helpful, man... anyway, are you really using a Forms 1.0 form?

Anonymous
Not applicable

Re: Using Javascript to Auto-Submit a form

Sanford, I'm using Forms 2.0. I'm lost an where to insert the js or jq snipet.

SanfordWhiteman
Level 10 - Community Moderator

Re: Using Javascript to Auto-Submit a form

Well, first of all, you can't use the Forms 1.0 script here -- and that's a good thing, because the Forms 2.0 API allows you to do this far more straightforwardly.

Can you lay out exactly what you're trying to do?  You want to a form to submit automatically (and not render) based on what criteria?

Anonymous
Not applicable

Re: Using Javascript to Auto-Submit a form

Kenny

I have a landing page the sends the requestor to an external URL. I know I can do an HTML redirect with a simple script uploaded into the marketo file library. I prefer to route the requestor via a landing page so I can track analytics. All requestors will be cookied.

The form submit button says if "not redirected in 10 secods click here" I need to make good on the promise of automatic redirection either instantly or with a delay timer.

So, in the end I could use js or jq code to get the submit button to auto submit to accomplish the redirection.

Jerry Cooper

Anonymous
Not applicable

Re: Using Javascript to Auto-Submit a form

Here is the landing page now Sawtooth Demo Request

I would like it to auto-submit.

SanfordWhiteman
Level 10 - Community Moderator

Re: Using Javascript to Auto-Submit a form

MktoForms2.whenReady(function(form){

     setTimeout(form.submit,10000);

});

Kenny_Elkington
Marketo Employee

Re: Using Javascript to Auto-Submit a form

Hey Neil,

If you're using Forms 2.0, there's a full API available for form manipulation which you can find here: http://developers.marketo.com/documentation/websites/forms-2-0/  The .submit() method provided to automatically initialize the submission process, as well as the .getValues() method if you want to pull a JS object to submit via your own Ajax methods.