Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glennyboy/7b368a3b957a156888923796eacc6ba3 to your computer and use it in GitHub Desktop.
Save glennyboy/7b368a3b957a156888923796eacc6ba3 to your computer and use it in GitHub Desktop.
Auto populate Webflow form from url parameter uppercase replace %20
// 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