Skip to content

Instantly share code, notes, and snippets.

@noahub
Last active November 28, 2018 18:26
Show Gist options
  • Select an option

  • Save noahub/cab64fcf0b05ead054be1ecc01cf6fe9 to your computer and use it in GitHub Desktop.

Select an option

Save noahub/cab64fcf0b05ead054be1ecc01cf6fe9 to your computer and use it in GitHub Desktop.

Revisions

  1. Noah revised this gist Sep 28, 2018. 1 changed file with 13 additions and 9 deletions.
    22 changes: 13 additions & 9 deletions form_submit.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    <script type="text/javascript">
    //runs on form submission
    function yourSubmitFunction(e, $) {
    e.preventDefault();
    try {
    @@ -15,15 +16,6 @@ function yourSubmitFunction(e, $) {
    }
    }

    lp.jQuery(function($) {
    $('.lp-pom-form .lp-pom-button').unbind('click tap touchstart').bind('click.formSubmit tap.formSubmit touchstart.formSubmit', function(e) {
    if ( $('.lp-pom-form form').valid() ) yourSubmitFunction(e, $);
    });
    $('form').unbind('keypress').bind('keypress.formSubmit', function(e) {
    if(e.which === 13 && e.target.nodeName.toLowerCase() !== 'textarea' && $('.lp-pom-form form').valid() )
    yourSubmitFunction(e, $);
    });
    });
    //ga form submission event
    function gaForm(event) {
    var $form, $formContainer, params;
    @@ -53,4 +45,16 @@ function gaForm(event) {
    }
    };

    //waits until window load to initialize
    lp.jQuery(window).load(function(){
    lp.jQuery(function($) {
    $('.lp-pom-form .lp-pom-button').unbind('click tap touchstart').bind('click.formSubmit tap.formSubmit touchstart.formSubmit', function(e) {
    if ( $('.lp-pom-form form').valid() ) yourSubmitFunction(e, $);
    });
    $('form').unbind('keypress').bind('keypress.formSubmit', function(e) {
    if(e.which === 13 && e.target.nodeName.toLowerCase() !== 'textarea' && $('.lp-pom-form form').valid() )
    yourSubmitFunction(e, $);
    });
    });
    });
    </script>
  2. Noah revised this gist Sep 26, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion form_submit.js
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ function yourSubmitFunction(e, $) {
    }

    lp.jQuery(function($) {
    $('.lp-pom-form .lp-pom-button').unbind('click tap touchstart').bind('click.formSubmit', function(e) {
    $('.lp-pom-form .lp-pom-button').unbind('click tap touchstart').bind('click.formSubmit tap.formSubmit touchstart.formSubmit', function(e) {
    if ( $('.lp-pom-form form').valid() ) yourSubmitFunction(e, $);
    });
    $('form').unbind('keypress').bind('keypress.formSubmit', function(e) {
  3. Noah revised this gist Sep 21, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion form_submit.js
    Original file line number Diff line number Diff line change
    @@ -32,6 +32,7 @@ function gaForm(event) {
    $formContainer = lp.jQuery(event.currentTarget).closest('.lp-pom-form');
    $form = $formContainer.children('form');
    if ($form.valid()) {
    if(typeof eventTracker !== 'undefined'){
    if (!eventTracker._isGaLoaded()) {
    return $form.submit();
    }
    @@ -46,7 +47,10 @@ function gaForm(event) {
    return $form.submit();
    }
    });
    }else{
    return $form.submit();
    }
    }
    };
    };

    </script>
  4. Noah revised this gist Aug 28, 2017. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions form_submit.js
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@ function yourSubmitFunction(e, $) {
    }
    finally {
    // This submits the form. If your code is asynchronous, add to callback instead
    gaForm(e);
    lp.jQuery('.lp-pom-form form').submit();
    }
    }
    @@ -23,4 +24,29 @@ lp.jQuery(function($) {
    yourSubmitFunction(e, $);
    });
    });
    //ga form submission event
    function gaForm(event) {
    var $form, $formContainer, params;
    event.preventDefault();
    event.stopPropagation();
    $formContainer = lp.jQuery(event.currentTarget).closest('.lp-pom-form');
    $form = $formContainer.children('form');
    if ($form.valid()) {
    if (!eventTracker._isGaLoaded()) {
    return $form.submit();
    }
    params = lp.jQuery.extend({
    category: 'Form',
    action: 'Submit',
    label: "#" + ($formContainer.attr('id'))
    }, $formContainer.data('ubGAParams'));
    eventTracker._logEvent(params);
    return ga('send', 'event', params.category, params.action, params.label, {
    hitCallback: function() {
    return $form.submit();
    }
    });
    }
    };

    </script>
  5. Noah created this gist Mar 29, 2017.
    26 changes: 26 additions & 0 deletions form_submit.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <script type="text/javascript">
    function yourSubmitFunction(e, $) {
    e.preventDefault();
    try {
    //ADD CUSTOM CODE HERE
    }
    catch(err) {
    //code to handle errors. console.log is just an example
    console.log(err);
    }
    finally {
    // This submits the form. If your code is asynchronous, add to callback instead
    lp.jQuery('.lp-pom-form form').submit();
    }
    }

    lp.jQuery(function($) {
    $('.lp-pom-form .lp-pom-button').unbind('click tap touchstart').bind('click.formSubmit', function(e) {
    if ( $('.lp-pom-form form').valid() ) yourSubmitFunction(e, $);
    });
    $('form').unbind('keypress').bind('keypress.formSubmit', function(e) {
    if(e.which === 13 && e.target.nodeName.toLowerCase() !== 'textarea' && $('.lp-pom-form form').valid() )
    yourSubmitFunction(e, $);
    });
    });
    </script>