简体   繁体   中英

How to get Marketo Form element's values in PHP

I have the marketo script

<script src="//app-abba.marketo.com/js/forms2/js/forms2.min.js"> </script> 
       <form id="mktoForm_id1"> </form> 
    <script>MktoForms2.loadForm("//app-aba.marketo.com", "xxx-XXX-xxx", id1);  </script>

Placing it in PHP\\Worpress displays all the Marketo fields along with the Submit button.

My Requirement

But before Submitting the Marketo Form

  1. I want to get the form elements values
  2. Do some calculation with the values
  3. Display the result on click of Marketo Submit Button.

Please give me details on how to implement this

You can use JavaScript to get all of the fields in the form and loop through them, using the elements property on the form.

Example:

var form = document.getElementById('mktoForm_id1');

console.log(form.elements); // contains all form fields.

Add a submit event listener to catch the values of the form fields before submitting.

Try this example.
This code will capture the form fields upon a successful form submission.
(Make sure you use your form's embed code)

 <script src="//xxxxx.marketo.com/js/forms2/js/forms2.min.js"></script> <form id="mktoForm_1"></form> <script> MktoForms2.loadForm("//app-sjqe.marketo.com", "123-ABC-456", 1, function(form) { form.onSubmit(function() { var vals = form.vals(); console.log(vals); }); }); </script> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM