Skip to content

Instantly share code, notes, and snippets.

@salsalabs
Last active September 15, 2017 14:51
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/7ee0028cba02e5b7a7d5 to your computer and use it in GitHub Desktop.
Save salsalabs/7ee0028cba02e5b7a7d5 to your computer and use it in GitHub Desktop.
Workaround script to provide event information for thank you pages and autoresponses.
<!-- BEGIN Additional fields for event autoresponses. -->
<?
// Script to retrieve the `event` record for an event registration.
// * The script only runs on event pages and event checkout pages. Nothing happens for other page types.
// * The script needs must be placed just before the end of the `body` tag in the template.
// * Javascript can access the stored data using `#eventDetails`.
//
// @see https://help.salsalabs.com/hc/en-us/articles/115000040193-Additional-merge-fields-for-event-autoresponses
//
var event = "null";
(function() {
var urlFlag = 'event/common/public';
if (Request.getURI().indexOf(urlFlag) == -1) { return; }
var eventKey = Request.getParameter('event_KEY');
if (eventKey == null) { return; }
var record = DB.getObject('event', eventKey);
if (record == null) { return; }
?>
<div id="eventDetails">
<?
var fields = "Event_Name,Location_Common_Name,Address,City,State,Zip,Country,Directions,Start,End".split(',');
var needPrefix = 'City,State,Country,Zip'.split(',');
eval(Crawler.get('https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js'));
for (key in record) {
if (fields.indexOf(key) != -1) {
var value = record[key];
if (key == 'Start' || key == 'End') {
value = moment(record[key]).format('MMMM D, YYYY [at] h:mm a');
}
if (needPrefix.indexOf(key) != -1) {
key = 'Event_' + key;
}
?><input type="hidden" name="<?= key ?>" value="<?= value ?>">
<?
}
}
?>
</div>
<script type="text/javascript">
// Script to update the event details with the total amount, then append them
// to the form. That will make all of the detail information available for
// an autoresponse.
$(document).ready(function () {
var amount = $('td.salsaCartAmount strong big');
if (amount.length != 0) {
amount = amount.eq(0).html().replace('$', '');
$('#eventDetails').append('<input type="hidden" name="Event_Amount" value="' + amount + '">');
$('#eventDetails').append('<input type="hidden" name="payment_type" value="creditCard">');
}
$('.salsa form').append($('#eventDetails'));
})
// Script to update the details payment type. You can use this in a conditional
// send to discriminate between invoiced attendees and ones whose fees were paid
// with a credit card.
$(document).ready(function () {
$("#invoiceRadio").click(function () {
$("#credit_card_information").hide();
$("#Status").val("Invoiced");
$('input[name="payment_type"]').val('invoice');
});
$("#ccRadio").click(function () {
$("#credit_card_information").show();
$("#Status").val("");
$('input[name="payment_type"]').val('creditCard');
});
});
</script>
<?
})();
?>
<!-- END Additional fields for event autoresponses. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment