Skip to content

Instantly share code, notes, and snippets.

@sterlingwes
Created January 3, 2016 21:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sterlingwes/84eb4c07b30ec7ee64a3 to your computer and use it in GitHub Desktop.
Save sterlingwes/84eb4c07b30ec7ee64a3 to your computer and use it in GitHub Desktop.
Squarespace Parse Query String and Prefill Email Field in Contact Form
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