Last active
May 12, 2020 13:56
-
-
Save glennyboy/7b368a3b957a156888923796eacc6ba3 to your computer and use it in GitHub Desktop.
Auto populate Webflow form from url parameter uppercase replace %20
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
// auto populate form from url parameter | |
function getParam(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } | |
Webflow.push(function() { | |
// Auto-populate form fields based on query string | |
$('input:text[name=name], input[type=email], select[name=treatment], textarea[name=enquiry]').each(function() { | |
/// take the param and make uppercase from (this.id); | |
var paramValue = getParam(this.id).replace(/\b[a-z]/g, function(txtVal) { | |
return txtVal.toUpperCase().replace(/%20/g, " "); // replace %20 with real space | |
}); // end make each word uppercase and remove %20 | |
if(this.value == "" && paramValue != "") this.value = paramValue; | |
// show in console | |
console.log(paramValue); | |
}); | |
}); | |
// usage | |
// ?dropdown=selectoption&name=glenn&email=webflow@slickmedia.co.uk&enquiry=text%20enquiry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment