Last active
May 30, 2025 23:39
-
-
Save rickalday/fbe79557ca97cd56a2961ed8ff187083 to your computer and use it in GitHub Desktop.
Populate Tributes from URL parameters
This file contains hidden or 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
/** | |
* EXAMPLE: https://example.com/donations/give-form/?tribute=yes&first=Peter&last=Joseph | |
**/ | |
add_action( 'givewp_donation_form_enqueue_scripts', function(){ | |
?> | |
<script> | |
document.addEventListener("DOMContentLoaded", function () { | |
// Helper function to get URL parameters | |
function getUrlParam(param) { | |
const params = new URLSearchParams(window.parent.location.search); | |
return params.get(param); | |
} | |
const tribute = getUrlParam("tribute"); | |
const first = getUrlParam("first"); | |
const last = getUrlParam("last"); | |
// If tribute=yes, click the radio button with ID enableTribute_0 | |
if (tribute === "yes") { | |
const radio = document.getElementById("enableTribute_0"); | |
if (radio) { | |
radio.click(); | |
// Fill the input with name=tributeFirstName | |
const firstNameInput = document.querySelector("input[name='tributeFirstName']"); | |
if (firstNameInput && first) { | |
firstNameInput.value = first; | |
} | |
// Fill the input with name=tributeLastName | |
const lastNameInput = document.querySelector("input[name='tributeLastName']"); | |
if (lastNameInput && last) { | |
lastNameInput.value = last; | |
} | |
} | |
} | |
}); | |
</script> | |
<?php | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment