Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. This script adds a custom handler to form submissions. The code will be run *before* Unbounce's form handler kicks in and *after* validation has been confirmed. This means it isn't suitable for navigating users away from the landing page (as this would likely happen before the data has been saved to Unbounce). However, it could be useful for sending data to analytics platforms, etc.
  2.  
  3. ```html
  4. <script type="text/javascript">
  5.  
  6. function yourSubmitFunction(e, $) {
  7. e.preventDefault();
  8.  
  9. // Your code goes here, e.g.:
  10. dataLayer.push({'event': 'gtm.formSubmit'});
  11.  
  12. // If your code is asynchronous, call this final line in your callback instead
  13. $('.lp-pom-form form').submit();
  14. }
  15.  
  16. lp.jQuery(function($) {
  17. $('.lp-pom-form .lp-pom-button').unbind('click').bind('click.formSubmit', function(e) {
  18. if ( $('.lp-pom-form form').valid() ) yourSubmitFunction(e, $);
  19. });
  20.  
  21. $('form').unbind('keypress').bind('keypress.formSubmit', function(e) {
  22. if(e.which === 13 && e.target.nodeName.toLowerCase() !== 'textarea' && $('.lp-pom-form form').valid() )
  23. yourSubmitFunction(e, $);
  24. });
  25. });
  26.  
  27. </script>
  28. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement