Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Last active December 19, 2022 16:27
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 nocodesupplyco/15d39b50cdb2767ef620dc5ac7dba978 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/15d39b50cdb2767ef620dc5ac7dba978 to your computer and use it in GitHub Desktop.
Set Hidden Input Value From URL Parameters
// Function to get URL parameter values
function getUrlParameter(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
var results = regex.exec(location.search);
return results === null
? ""
: decodeURIComponent(results[1].replace(/\+/g, " "));
}
// Get name and email from URL and add to hidden inputs
$(function () {
if (window.location.href.indexOf("?name=") > -1) {
const name = getUrlParameter("name");
document.getElementById("creator-name").value = name;
const email = getUrlParameter("email");
document.getElementById("creator-email").value = email;
} else {
window.location.replace("https://webflow-pitch.webflow.io/");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment