Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.