Passing TOTAL to redirect (URL) - formatting issues

I’ve seen several related posts, but they haven’t quite solved this problem. Let’s say my total is $123.45. The value I need to pass to a 3rd party payment gateway (Tithely) via a URL is 12345 - no dollar sign, no periods, no commas.

I got almost there by creating a calculated number field (Total*100), but the number field format insists on inserting a comma “12,345”. How can I get a clean 12345 out of a $123.45 total?

Thanks in advance.

I found a solution and am posting it here for the benefit of anyone else who might need to do something like this:

First, start by creating a single line text field on the form. Make it hidden, and on Field Settings > Appearance, under Custom CSS Class, enter ‘tithely-total’ (without the quotes. This lets the javascript find this field.

This, I installed a plugin called SNIPPETS which allows me to insert code across all pages. I chose the option to insert this code at the end of the section of pages. This code will run when someone clicks the SUMBIT button, and shove the reformatted total into the hidden field. Here’s the code:

The last bit of the solution is to edit the form’s confirmation setting. Confirmation type should be “redirect”, the redirect URL should be the URL to your custom Tithely giving form, and the Pass Field Data via Query String value should be set to &amount={hidden-field-name:number}. You can get the right field reference by clicking the Insert Merge Tags button that’s just above the Pass Field Data box. It all works perfectly. Good luck!

Hmmm - code didn’t get included above. Trying again. Put this inside script /script tags:

document.addEventListener(‘gform/theme/scripts_loaded’, () => {
gform.utils.addAsyncFilter(‘gform/submission/pre_submission’, async (data) => {
const formId = data.form.dataset.formid;
const form = document.getElementById(‘gform_’ + formId);
if (!form) {
console.error(‘Form not found:’, formId);
return;
}
const gFormTotal = form.querySelector(‘.ginput_total’); // Get the form’s Total field
const tithelyTotal = form.querySelector(‘.tithely-total input’); // Get the hidden field to hold the Tithely formatted total
if (gFormTotal && tithelyTotal) {
const raw = gFormTotal.textContent.replace(/[^0-9.]/g, ‘’); // Get rid of $ and , characters in the form total
tithelyTotal.value = Math.round(parseFloat(raw) * 100); // Turn value into cents (what Tithely URL parameter requires)
} else {
console.warn(‘Total or tithelyTotal field not found’);
}
return data;
});
});

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.