Skip to content

Instantly share code, notes, and snippets.

@jhubert
Created March 30, 2012 00:47
Show Gist options
  • Save jhubert/2245397 to your computer and use it in GitHub Desktop.
Save jhubert/2245397 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
/*
Copyright (c) 2012 Jeremy Hubert (http://github.com/jhubert)
Released under the MIT License. See LICENSE for details.
*/
(function(a){a.fn.GoogleizeForm=function(c){var f,e,d,b;d=a.extend({},a.fn.GoogleizeForm.defaults,c);b=function(g){var h;if(g===""){return false}h=d.emailRegex;return h.test(g)};f=function(h,i,g){return d.success()};e=function(i){var g,h;i.preventDefault();h=a(this);g=h.find(d.emailFieldSelector);if(!b(g.val())){d.invalidEmail(g);return false}c={};c.type="POST";c.dataType="jsonp";c.url=h.attr("action");c.data=h.serialize();c.error=f;a.ajax(c)};return this.each(function(){return a(this).on("submit",e)})};a.fn.GoogleizeForm.defaults={emailRegex:/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/,emailFieldSelector:"#entry_0",success:function(){},invalidEmail:function(b){}}})(jQuery);
$(document).ready(function () {
$('form').GoogleizeForm({
success: function () {
$('#entry_0').val('');
$('#EmailSubmitted').show();
},
invalidEmail: function () {
alert('Your email address does not compute. Please retry.');
field.focus();
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment