Skip to content

Instantly share code, notes, and snippets.

@salsalabs
Created August 3, 2020 22:14
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 salsalabs/73ab495a31dc1827bede1892e812a6d7 to your computer and use it in GitHub Desktop.
Save salsalabs/73ab495a31dc1827bede1892e812a6d7 to your computer and use it in GitHub Desktop.
Supply/fill Country field on the Welcome Back pages. We need this because the Welcome Back page does not cache Country (known issue).
<?
// SalsaScript to check if the supporter is logged in. If so,
// it deposits the script that populates/appends the Country field.
(function() {
var country = null;
if (Supporter == null) { return; }
country = Supporter.get("Country");
country = (country == null) ? "US" : country;
?>
<!-- BEGIN Supply/fill country field on Welcome Back pages. -->
<script type="text/javascript">
(function (country) {
document.addEventListener("DOMContentLoaded", () => {
var f = document.querySelector('form[name="subform"]');
if (f == null) { return; }
var e = document.querySelector('*[name="Country"]');
if (e != null) {
e.value = country;
} else {
e = document.createElement("input");
e.type = "hidden";
e.name = "Country";
e.value = country;
f.appendChild(e);
}
});
})("<?= country ?>");
</script>
<!-- END Supply/fill country field on Welcome Back pages. -->
<?
})();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment