The client wanted data on what users are purchasing or which products they added to a quote request.
Able to create a code that will incorporate the “product list” data within the request a quote form submission, and pass it to LeadManagerFX.
Able to capture the “Product List” Data through the Request a Quote lead submission
Ticket: https://app.webfx.com/todos/269197916
Custom Code:
(function() {
console.log(‘[RFQ RCFX] Quote form capture script starting…’);
// Function to extract products and quantities
function extractProducts() {
console.log(‘[RFQ RCFX] Extracting products…’);
var products = [];
var productRows = document.querySelectorAll(‘.omgrfq_product_row’);
console.log(‘[RFQ RCFX] Found’, productRows.length, ‘product rows’);
productRows.forEach(function(row, index) {
// Get product title
var titleLink = row.querySelector(‘.omgrfq_product_title a’);
var productTitle = titleLink ? titleLink.textContent.trim() : ”;
// Get product option/variant
var optionEl = row.querySelector(‘.omgrfq_option’);
var productOption = optionEl ? optionEl.textContent.trim() : ”;
// Get quantity input
var qtyInput = row.querySelector(‘.item_qty’);
var quantity = qtyInput ? qtyInput.value : ‘0’;
// Get product ID from input ID (e.g., “updates_40993103151240″)
var productId = qtyInput ? qtyInput.id.replace(‘updates_’, ”) : ”;
console.log(‘[RFQ RCFX] Product’, index + 1 + ‘:’, {
title: productTitle,
option: productOption,
quantity: quantity,
id: productId
});
products.push({
title: productTitle,
option: productOption,
quantity: quantity,
id: productId
});
});
return products;
}
// Function to format products for RCFX
function formatProductsForRCFX(products) {
var formatted = products.map(function(product) {
var text = product.title;
if (product.option) {
text += ‘ – ‘ + product.option;
}
text += ‘ (Qty: ‘ + product.quantity + ‘)’;
return text;
}).join(‘ | ‘);
console.log(‘[RFQ RCFX] Formatted products:’, formatted);
return formatted;
}
// Function to handle form submission
function handleFormSubmit(event) {
console.log(‘[RFQ RCFX] ⚡ Form submission detected!’);
var form = event.target;
// Check if this is the RFQ form
if (!form.id || form.id !== ‘omgrfq-quote-list-form’) {
console.log(‘[RFQ RCFX] Not the RFQ form, skipping’);
return;
}
console.log(‘[RFQ RCFX] ✓ RFQ form confirmed’);
// Extract products
var products = extractProducts();
if (products.length === 0) {
console.log(‘[RFQ RCFX] ⚠️ No products found in cart’);
}
// Create virtual form for RCFX
var virtualForm = document.createElement(‘form’);
virtualForm.setAttribute(‘id’, ‘fx-rfq’);
console.log(‘[RFQ RCFX] Creating virtual form…’);
// Get all form fields
var formFields = form.querySelectorAll(‘input[id^=”omgrfq-form_”], select[id^=”omgrfq-select-country”]’);
console.log(‘[RFQ RCFX] Found’, formFields.length, ‘form fields’);
formFields.forEach(function(field) {
// Skip hidden captcha fields
if (field.id === ‘ot-response-captcha’) {
return;
}
var fieldId = field.getAttribute(‘id’);
var fieldLabel = ”;
// Try to find label
var label = form.querySelector(‘label[for=”‘ + fieldId + ‘”]’);
if (label) {
fieldLabel = label.textContent.replace(‘*’, ”).trim();
}
// Create new field for virtual form
var newField = document.createElement(‘input’);
newField.type = ‘text’;
// Use label as field name, fallback to ID
newField.name = fieldLabel || fieldId;
// Get value
var fieldValue = field.value || ”;
// For select dropdown (country), get selected option text
if (field.tagName === ‘SELECT’) {
var selectedOption = field.options[field.selectedIndex];
fieldValue = selectedOption ? selectedOption.textContent : fieldValue;
}
newField.value = fieldValue;
newField.setAttribute(‘value’, fieldValue);
console.log(‘[RFQ RCFX] Field captured:’, {
name: newField.name,
value: fieldValue
});
virtualForm.appendChild(newField);
});
// Add products as a single field
if (products.length > 0) {
var productsField = document.createElement(‘input’);
productsField.type = ‘hidden’;
productsField.name = ‘products’;
productsField.value = formatProductsForRCFX(products);
productsField.setAttribute(‘value’, productsField.value);
virtualForm.appendChild(productsField);
console.log(‘[RFQ RCFX] ✓ Products field added’);
// Also add individual product quantity fields
products.forEach(function(product, index) {
var productField = document.createElement(‘input’);
productField.type = ‘hidden’;
productField.name = ‘product_’ + (index + 1);
productField.value = product.title + ‘ – ‘ + product.option + ‘ (Qty: ‘ + product.quantity + ‘)’;
productField.setAttribute(‘value’, productField.value);
virtualForm.appendChild(productField);
// Add quantity as separate field
var qtyField = document.createElement(‘input’);
qtyField.type = ‘hidden’;
qtyField.name = ‘product_’ + (index + 1) + ‘_quantity’;
qtyField.value = product.quantity;
qtyField.setAttribute(‘value’, product.quantity);
virtualForm.appendChild(qtyField);
});
console.log(‘[RFQ RCFX] ✓ Individual product fields added’);
}
// Add page URL
var urlField = document.createElement(‘input’);
urlField.type = ‘hidden’;
urlField.name = ‘formSubmissionPage’;
urlField.value = window.location.href;
virtualForm.appendChild(urlField);
// Add timestamp
var timestampField = document.createElement(‘input’);
timestampField.type = ‘hidden’;
timestampField.name = ‘submission_timestamp’;
timestampField.value = new Date().toISOString();
virtualForm.appendChild(timestampField);
console.log(‘[RFQ RCFX] Virtual form HTML:’, virtualForm.innerHTML.substring(0, 300) + ‘…’);
// Capture with RCFX
if (typeof mcfx !== ‘undefined’) {
mcfx(function(tracker) {
tracker.capture(virtualForm);
console.log(‘[RFQ RCFX] ✓✓✓ RCFX capture success!’);
});
} else {
console.log(‘[RFQ RCFX] ✗ MCFX not available’);
}
// Log summary
console.log(‘[RFQ RCFX] === CAPTURE SUMMARY ===’);
console.log(‘[RFQ RCFX] Form ID: fx-rfq’);
console.log(‘[RFQ RCFX] Products:’, products.length);
console.log(‘[RFQ RCFX] Form Fields:’, formFields.length);
}
// Attach to form submit event
document.addEventListener(‘submit’, handleFormSubmit, true);
console.log(‘[RFQ RCFX] ✓ Submit listener attached’);
// Also listen for button clicks (in case form doesn’t fire submit event)
document.addEventListener(‘click’, function(event) {
if (event.target.matches(‘#submitOMGRFQForm, button[name=”submitOMGRFQForm”]’)) {
console.log(‘[RFQ RCFX] Submit button clicked directly’);
// Small delay to let any validation complete
setTimeout(function() {
var form = document.querySelector(‘#omgrfq-quote-list-form’);
if (form) {
handleFormSubmit({ target: form });
}
}, 100);
}
});
console.log(‘[RFQ RCFX] ✓ Script loaded and initialized’);
})();