Last active
December 13, 2022 11:39
-
-
Save VijayaSankarN/1418e856400eb24efc39deadd5f00081 to your computer and use it in GitHub Desktop.
Salesforce: Submit Web2Lead without reloading or refreshing the page. Details: https://vijayasankarn.wordpress.com/2022/12/13/salesforce-web-to-lead-case-without-refreshing-the-page/
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
<!DOCTYPE html> | |
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" /> | |
</head> | |
<body> | |
<form id="web2leadForm" action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST"> <!-- Update with the Salesforce-defined value for the action attribute --> | |
<input type="hidden" name="oid" id="oid" value="" /> <!-- Enter Org ID in the value --> | |
<input type="hidden" name="retURL" id="retURL" value="http://example.com" /> <!-- Update the return URL value --> | |
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br /> | |
<label for="company">Company</label><input id="company" maxlength="40" name="company" size="20" type="text" /><br /> | |
<label for="email">Email</label><input id="email" maxlength="80" name="email" size="20" type="text" /><br /> | |
<input type="submit" id="submitButton" value="Subscribe" /> | |
</form> | |
<script> | |
window.onload = function () { | |
document.querySelector("#web2leadForm").onsubmit = function (e) { | |
e.preventDefault(); | |
// Create an iframe | |
document.querySelectorAll("#web2leadIFrame").length && document.querySelector("#web2leadIFrame").remove(); // Remove the iframe if already exists | |
var web2leadIFrame = document.createElement("iframe"); | |
web2leadIFrame.id = "web2leadIFrame"; | |
web2leadIFrame.style.display = "none"; | |
document.body.appendChild(web2leadIFrame); | |
// Append values and submit | |
var web2leadIFrame = document.querySelector("#web2leadIFrame"); | |
var web2leadIFrameContent = web2leadIFrame.contentDocument || web2leadIFrame.contentWindow.document; | |
web2leadIFrameContent.body.appendChild(document.querySelector("#web2leadForm").cloneNode(true)); | |
web2leadIFrameContent.body.querySelector("#web2leadForm").submit(); | |
// Reset the current Form | |
document.querySelector("#web2leadForm").reset(); | |
}; | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment