Figer's Technology Consulting | Using Google Docs Forms to validate email addreses, capture them and redirect to your site

Using Google Docs Forms to validate email addreses, capture them and redirect to your site

I wanted to allow the user to hit index.html and if it was the first time visiting the site, they'd have to type in their email address (which I was validating with Javascript), then redirecting to an agreement page, otherwise if they had been there before based on a cookie I had created redirect them immediately to inner_index.html. The Problem: Google Docs don't want you to redirect after the form is submitted, Google docs don't play very nicely with IE when you try to implement work arounds.

The Solution:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/spreadsheets/forms/favicon_jfk.png" type="image/x-icon">
<title>Title</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="description" content="">
<meta name="keywords" content="">
<link rel="shortcut icon" href="images/favicon.ico" />
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
</head>
<body onload="checkCookie()" dir="ltr" itemscope itemtype="http://schema.org/CreativeWork/FormObject"><meta itemprop="name" content="Email Capture Form">
<meta itemprop="thumbnailUrl" content="https://docs.google.com/spreadsheet/formthumb?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ">
<meta itemprop="embedUrl" content="https://docs.google.com/spreadsheet/embeddedform?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ">
<meta itemprop="faviconUrl" content="//ssl.gstatic.com/docs/spreadsheets/forms/favicon_jfk.png">
<div>
<div><script type="text/javascript">var submitted_jljnpsrw=false;function
checkRequiredFields_jljnpsrw(requiredFields)
{
var errorMessage='Required field left blank.';
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.getElementById('entry_0').value;
if (reg.test(address) == false)
{
alert("Not a valid e-mail address");
return false;
}
for(var x in requiredFields)
{
var fieldNum=requiredFields[x];
if(document.getElementById('entry_'+fieldNum))
{
if(!document.getElementById('entry_'+fieldNum).value.length)
{
alert(errorMessage);
document.getElementById('entry_'+fieldNum).focus();
return false;
}
}
else if(document.getElementById('group_'+fieldNum+'_1'))
{
var counter=1;
var selected=false;
while(document.getElementById('group_'+fieldNum+'_'+counter))
{
if(document.getElementById('group_'+fieldNum+'_'+counter).checked)
{
selected=true;
}
counter++;
}
if(document.getElementById('other_option:'+fieldNum))
{
if(document.getElementById('other_option:'+fieldNum).checked)
{
selected=true;
if(!document.getElementsByName('entry.'+fieldNum+'.group.other_option_').item(0).value.length)
{
alert(errorMessage);
document.getElementsByName('entry.'+fieldNum+'.group.other_option_').item(0).focus();
return false;
}
}
}
if(!selected)
{
alert(errorMessage);
document.getElementById('group_'+fieldNum+'_1').focus();
return false;
}
}
}
var today = new Date();
var expire = new Date();
expire.setTime(today.getTime() + 3600000*24*365);
document.cookie = "33poemsEmail=BeenHere;expires="+expire.toGMTString();
return true;
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
function checkCookie()
{
var email=getCookie("33poemsEmail");
if (email!=null && email!="")
{
window.location = "inner_index.html";
}
}
</script>
<p>Title</p>
<p>Sub-Title</p>
<div id="description">
<div>
<p><span>T</span>his is where you put the description</p>
<iframe name="hidden_iframe_jljnpsrw" id="hidden_iframe_jljnpsrw" style="display:none;" onload="if(submitted_jljnpsrw){window.location='foc.html';}"></iframe><form action="https://docs.google.com/spreadsheet/formResponse?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ&amp;ifq" method="post" target="hidden_iframe_jljnpsrw" onsubmit="if(checkRequiredFields_jljnpsrw([0])){submitted_jljnpsrw=true;}else{return false;}" id="ss-form">
<br>
<div>
<div><div>
<label for="entry_0"></label>
<div>Please enter your email address to enter the site<br></div>
<div><input type="text" name="entry.0.single" value="" id="entry_0"><input type="submit" name="submit" value="Submit"></div>
</div></div></div>
<br>
<input type="hidden" name="pageNumber" value="0">
<input type="hidden" name="backupCache" value="">
<div><div>
</div></div></form>
<script type="text/javascript">
(function() {
var divs = document.getElementById('ss-form').
getElementsByTagName('div');
var numDivs = divs.length;
for (var j = 0; j < numDivs; j++) {
if (divs[j].className == 'errorbox-bad') {
divs[j].lastChild.firstChild.lastChild.focus();
return;
}
}
for (var i = 0; i < numDivs; i++) {
var div = divs[i];
if (div.className == 'ss-form-entry' &&
div.firstChild &&
div.firstChild.className == 'ss-q-title') {
div.lastChild.focus();
return;
}
}
})();
</script></div>
</div></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/spreadsheets/forms/favicon_jfk.png" type="image/x-icon"><title>Title</title>    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />    <meta name="description" content="">    <meta name="keywords" content="">    <link rel="shortcut icon" href="images/favicon.ico" />    <link rel="stylesheet" href="style.css" type="text/css" media="all" /></head><body onload="checkCookie()" dir="ltr" itemscope itemtype="http://schema.org/CreativeWork/FormObject"><meta itemprop="name" content="Email Capture Form"> <meta itemprop="thumbnailUrl" content="https://docs.google.com/spreadsheet/formthumb?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ"> <meta itemprop="embedUrl" content="https://docs.google.com/spreadsheet/embeddedform?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ"><meta itemprop="faviconUrl" content="//ssl.gstatic.com/docs/spreadsheets/forms/favicon_jfk.png"> <div><div><script type="text/javascript">var submitted_jljnpsrw=false;function checkRequiredFields_jljnpsrw(requiredFields){ var errorMessage='Required field left blank.'; var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var address = document.getElementById('entry_0').value; if (reg.test(address) == false)  {  alert("Not a valid e-mail address"); return false;  } for(var x in requiredFields) { var fieldNum=requiredFields[x]; if(document.getElementById('entry_'+fieldNum)) { if(!document.getElementById('entry_'+fieldNum).value.length) { alert(errorMessage); document.getElementById('entry_'+fieldNum).focus(); return false; } } else if(document.getElementById('group_'+fieldNum+'_1')) { var counter=1; var selected=false; while(document.getElementById('group_'+fieldNum+'_'+counter)) { if(document.getElementById('group_'+fieldNum+'_'+counter).checked) { selected=true; } counter++; } if(document.getElementById('other_option:'+fieldNum)) { if(document.getElementById('other_option:'+fieldNum).checked) { selected=true; if(!document.getElementsByName('entry.'+fieldNum+'.group.other_option_').item(0).value.length) { alert(errorMessage); document.getElementsByName('entry.'+fieldNum+'.group.other_option_').item(0).focus(); return false; } } } if(!selected) { alert(errorMessage); document.getElementById('group_'+fieldNum+'_1').focus(); return false; } } } var today = new Date();  var expire = new Date();  expire.setTime(today.getTime() + 3600000*24*365);  document.cookie = "33poemsEmail=BeenHere;expires="+expire.toGMTString(); return true;} function getCookie(c_name){var i,x,y,ARRcookies=document.cookie.split(";");for (i=0;i<ARRcookies.length;i++)  {  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);  x=x.replace(/^\s+|\s+$/g,"");  if (x==c_name)    {    return unescape(y);    }  }} function checkCookie(){ var email=getCookie("33poemsEmail");if (email!=null && email!="")  {  window.location = "inner_index.html";  }}</script>      <p>Title</p>      <p>Sub-Title</p>      <div id="description">        <div>          <p><span>T</span>his is where you put the description</p> <iframe name="hidden_iframe_jljnpsrw" id="hidden_iframe_jljnpsrw" style="display:none;" onload="if(submitted_jljnpsrw){window.location='foc.html';}"></iframe><form action="https://docs.google.com/spreadsheet/formResponse?formkey=dElxTGNKYTFoWkxSOVVwb3RiR210Wnc6MQ&amp;ifq" method="post" target="hidden_iframe_jljnpsrw" onsubmit="if(checkRequiredFields_jljnpsrw([0])){submitted_jljnpsrw=true;}else{return false;}" id="ss-form"> <br><div><div><div><label for="entry_0"></label> <div>Please enter your email address to enter the site<br></div> <div><input type="text" name="entry.0.single" value="" id="entry_0"><input type="submit" name="submit" value="Submit"></div> </div></div></div><br><input type="hidden" name="pageNumber" value="0"><input type="hidden" name="backupCache" value=""> <div><div></div></div></form><script type="text/javascript">            (function() {var divs = document.getElementById('ss-form').getElementsByTagName('div');var numDivs = divs.length;for (var j = 0; j < numDivs; j++) {if (divs[j].className == 'errorbox-bad') {divs[j].lastChild.firstChild.lastChild.focus();return;}}for (var i = 0; i < numDivs; i++) {var div = divs[i];if (div.className == 'ss-form-entry' &&div.firstChild &&div.firstChild.className == 'ss-q-title') {div.lastChild.focus();return;}}})();      
</script>
</div>
</div>
</body>
</html>
Comments are closed