Architect requested that the booth configuration details (booth type, size, colors, add-ons, prices, etc.) shown in the client’s site notification also be captured in LeadManagerFX. Only the name, email and phone were captured, and the details are needed for the Nutshell connected forms.
The booth details were not captured because they are not part of the form. They are only shown in the quote summary.
I added a custom script in WordPress’ RCFX Settings Footer that reads the quote summary and adds the details as hidden inputs to the Customer Info form when it is captured.
Features with multiple entries are saved comma-separated, together with their prices. Then I updated the mapped form.
(function () {
var PREFIX = 'rcfx-input-';
var GROUPS = [
['size', 'summary-size-label', 'summary-size-price'],
['colors', 'summary-colors', 'summary-colors-price'],
['doors', 'summary-doors', 'summary-doors-price'],
['windows', 'summary-windows', 'summary-windows-price'],
['roof', 'summary-roof', 'summary-roof-price'],
['exterior-addon', 'summary-exterior-addon', 'summary-exterior-addon-price'],
['windows-feature', 'summary-windows-feature', 'summary-windows-feature-price'],
['heating-cooling', 'summary-heating-cooling', 'summary-heating-cooling-price'],
['electricity', 'summary-electricity', 'summary-electricity-price'],
['interior-addon', 'summary-interior-addon', 'summary-interior-addon-price']
];
function clean(s) {
return (s || '').replace(/[u00a0u200b]/g, ' ').replace(/s+/g, ' ').replace(/^s+|s+$/g, '');
}
function baseUrl() {
return window.location.href.split('#')[0].split('?')[0];
}
function summaryTable() {
return document.querySelector('.summary-table');
}
function rowByLabel(label) {
var t = summaryTable();
if (!t) return null;
for (var i = 0; i < t.rows.length; i++) {
var c = t.rows[i].cells[0];
if (c && clean(c.textContent).toUpperCase().indexOf(label) === 0) return t.rows[i];
}
return null;
}
function cellText(row, index) {
if (!row || !row.cells || !row.cells[index]) return '';
return clean(row.cells[index].textContent);
}
function itemsOf(el) {
var out = [];
if (!el) return out;
var divs = [];
var i;
for (i = 0; i < el.children.length; i++) {
if (el.children[i].tagName === 'DIV') divs.push(el.children[i]);
}
if (!divs.length) divs = [el];
for (i = 0; i < divs.length; i++) {
var node = divs[i];
var spans = node.getElementsByTagName('span');
var quoted = false;
var detail = '';
for (var j = 0; j < spans.length; j++) {
var st = clean(spans[j].textContent);
if (!st) continue;
if (st.toLowerCase() === 'to be quoted') quoted = true;
else detail = detail ? detail + '; ' + st : st;
}
var copy = node.cloneNode(true);
var strip = copy.getElementsByTagName('span');
while (strip.length) strip[0].parentNode.removeChild(strip[0]);
out.push({ name: clean(copy.textContent), detail: detail, quoted: quoted });
}
return out;
}
function category(labelId, priceId) {
var items = itemsOf(document.getElementById(labelId));
var prices = itemsOf(document.getElementById(priceId));
var names = [];
var costs = [];
var pi = 0;
for (var i = 0; i < items.length; i++) {
var it = items[i];
if (!it.name || it.name === '-') continue;
names.push(it.detail ? it.name + ' (' + it.detail + ')' : it.name);
if (it.quoted) {
costs.push('To be quoted');
} else if (pi < prices.length) {
costs.push(prices[pi].name);
pi++;
} else {
costs.push('');
}
}
return { value: names.join(', '), price: costs.join(', ') };
}
function collect() {
var data = {};
if (!summaryTable()) return data;
var i;
for (i = 0; i < GROUPS.length; i++) {
var g = category(GROUPS[i][1], GROUPS[i][2]);
data[PREFIX + GROUPS[i][0]] = g.value;
data[PREFIX + GROUPS[i][0] + '-price'] = g.price;
}
data[PREFIX + 'booth-type'] = cellText(rowByLabel('BOOTH TYPE'), 1);
var ship = rowByLabel('SHIPPING');
data[PREFIX + 'shipping'] = cellText(ship, 1);
data[PREFIX + 'shipping-price'] = cellText(ship, 2);
var tax = document.getElementById('summary-tax-amount');
var taxLoc = document.getElementById('summary-tax-location');
var taxVal = tax ? clean(tax.textContent) : '';
var locVal = taxLoc ? clean(taxLoc.textContent) : '';
data[PREFIX + 'estimated-taxes'] = locVal ? taxVal + ' (' + locVal + ')' : taxVal;
var sub = document.querySelector('.summary-content__subtotal-value');
data[PREFIX + 'subtotal'] = sub ? clean(sub.textContent) : '';
var exempt = document.getElementById('tax-exempt');
data[PREFIX + 'tax-exempt'] = exempt ? (exempt.checked ? 'Yes' : 'No') : '';
var comments = document.getElementById('additional-comments');
data[PREFIX + 'additional-comments'] = comments ? clean(comments.value) : '';
data[PREFIX + 'configuration-url'] = baseUrl();
return data;
}
function inject(form) {
if (!form || form.id !== 'customer-info-form') return;
var data = collect();
var added = [];
var k;
for (k in data) {
if (!data.hasOwnProperty(k)) continue;
var val = data[k];
if (!val) continue;
if (form.querySelector('input[name="' + k + '"]')) continue;
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', k);
input.setAttribute('value', val);
form.appendChild(input);
added.push(input);
}
if (!added.length) return;
setTimeout(function () {
for (var i = 0; i < added.length; i++) {
if (added[i].parentNode) added[i].parentNode.removeChild(added[i]);
}
}, 0);
}
function nameless(form) {
var counter = 1;
var els = form.querySelectorAll('input, select, textarea');
for (var i = 0; i < els.length; i++) {
if (!els[i].name) els[i].name = els[i].id ? els[i].id : 'rcfx-custom-id-' + counter++;
}
}
function bindCapture() {
if (typeof window.mcfx !== 'function') return false;
window.mcfx(function (t) {
t.configure('onFormCapture', function (form) {
nameless(form);
inject(form);
});
});
return true;
}
window.gbQuoteCollect = collect;
window.gbQuoteInject = inject;
if (!bindCapture()) {
var tries = 0;
var timer = setInterval(function () {
tries++;
if (bindCapture() || tries > 60) clearInterval(timer);
}, 500);
}
})();
The booth configuration details and their prices are now captured in LeadManagerFX together with the customer info.
Task: Link
Code: Screenshot