Skip to content

Instantly share code, notes, and snippets.

@salsalabs
Created February 10, 2016 22:34
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/59471d0b796a6002abea to your computer and use it in GitHub Desktop.
Save salsalabs/59471d0b796a6002abea to your computer and use it in GitHub Desktop.
Script to accept &uid=whatever and store it into the new donation's uid field.
<script type="text/javascript">
// Add donation.uid to the form and populate it with the contents of the
// `uid` query in the URL.
// @see https://salsasupport.zendesk.com/entries/98784548
$(document).ready(function() {
if (window.location.href.indexOf('public/?donate_page_KEY=') == -1) {
return;
}
var searches = window.location.search.split('&')
.reduce(function(a, x) {
var parts = x.split('=');
a[parts[0]] = (parts.length > 1) ? parts.splice(1).join('=') : null;
return a;
}, {});
if (searches.hasOwnProperty('uid')) {
// @note The UID *must* appear at the end of the form. If it's not there
// then Salsa will apply it to the supporter record.
$('form[name=subform]').append(''
+ '<input type="hidden" name="object" value="donation"/>'
+ '<input type="hidden" name="uid" value="' + searches['uid'] + '"/>');
};
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment