Skip to content

Instantly share code, notes, and snippets.

@renemorozowich
Created April 12, 2025 17:47
Show Gist options
  • Save renemorozowich/de60817f659e986ba1df8c928c76659b to your computer and use it in GitHub Desktop.
Save renemorozowich/de60817f659e986ba1df8c928c76659b to your computer and use it in GitHub Desktop.
Validate Gravity Forms fields
<script>
document.addEventListener("DOMContentLoaded", checkPage);
function checkPage() {
document.getElementById("gform_submit_button_2").style.display = 'none';
}
// first name
document.getElementById("input_2_1_3").addEventListener("change", checkFields);
// last name
document.getElementById("input_2_1_6").addEventListener("change", checkFields);
// company
document.getElementById("input_2_4").addEventListener("change", checkFields);
function checkFields() {
var fn = document.getElementById("input_2_1_3").value;
var ln = document.getElementById("input_2_1_6").value;
var fullName;
var company = document.getElementById("input_2_4").value;
var nameCheck;
//console.log("fn:" + fn);
//console.log("ln:" + ln);
fullName = fn + " " + ln;
//console.log("fulln:" + fullName);
// if fields have content
if (fn && ln && company) {
// don't show if first = last
if (fn == ln) {
nameCheck = false;
// don't show if full name = company
} else if (fullName == company) {
nameCheck = false;
} else {
nameCheck = true;
}
}
if (nameCheck == true) {
document.getElementById("gform_submit_button_2").style.display = 'block';
} else {
document.getElementById("gform_submit_button_2").style.display = 'none';
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment