Advertisement
briank

Kartra Forms - Capture fields to local storage

Nov 4th, 2019
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (window.localStorage) {
  2.   $(function () {
  3.     function enableCaptureOnSubmit () {
  4.       $('form').off('.field-capture');
  5.       $('form').on('submit.field-capture', function () {
  6.         var $this = $(this);
  7.         var name = $this.find('input[placeholder*="First name"]').val(); // Adjust these to match as necessary
  8.         var email = $this.find('input[placeholder*="Email address"]').val();
  9.         if (undefined !== name && undefined !== email) {
  10.           localStorage.setItem('optin-name', name);
  11.           localStorage.setItem('optin-email', email);
  12.         }
  13.       });
  14.     }
  15.     setTimeout(enableCaptureOnSubmit, 0);
  16.     try {
  17.       var bmo = new MutationObserver(enableCaptureOnSubmit);
  18.       bmo.observe(document.body, { childList: true, subtree: true });
  19.     } catch (e) {}
  20.   });
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement