Created
January 3, 2016 21:06
-
-
Save sterlingwes/84eb4c07b30ec7ee64a3 to your computer and use it in GitHub Desktop.
Squarespace Parse Query String and Prefill Email Field in Contact Form
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
function parseSearchString () { | |
var qs = window.location.search | |
qs = qs.replace(/^\?/,'') | |
var parts = qs.split('&') | |
var params = {} | |
parts.forEach(function (part) { | |
var pair = part.split('=') | |
params[pair[0]] = decodeURIComponent(pair[1]) | |
}) | |
return params | |
} | |
window.onload = function () { | |
var qs = parseSearchString() | |
if (qs.SQF_USER_EMAIL) { | |
var el = document.querySelectorAll('input[name=email]') | |
if (!el.length) return | |
el[0].value = qs.SQF_USER_EMAIL | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment