Created
March 30, 2012 00:47
-
-
Save jhubert/2245397 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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