Last active
August 29, 2015 14:22
-
-
Save shrunyan/1e8933f089cb3256fa4c to your computer and use it in GitHub Desktop.
jQuery script which will post a form to another url before posting to the default action attribute. Being used to capture a form lead submission to both the first party platform as well as Salesforce.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
// Using jQuery Library | |
$('#salesforce-form').one('submit', function(e) { | |
e.preventDefault(); | |
var $form = $(this); | |
$.ajax({ | |
url: '{{ page.getUrl() }}', | |
type: 'POST', | |
data: $form.serialize(), | |
success: function cb() { | |
$form.trigger('submit'); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
one
method will attach our on submit callback and detach it after it's been executed. So our callback code is triggered. Which just posts the form data to the current page. The callback is detached and we trigger another form submit which will cause the normal form submissionaction
post to occur.We're using Parsley to get a reference to the current page url.