Skip to content

Instantly share code, notes, and snippets.

@shrunyan
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrunyan/1e8933f089cb3256fa4c to your computer and use it in GitHub Desktop.
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.
<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>
@shrunyan
Copy link
Author

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 submission action post to occur.

We're using Parsley to get a reference to the current page url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment