Make CRM exports download reliably
All checks were successful
Test and publish WordPress plugin / release (push) Successful in 19s

This commit is contained in:
josh
2026-11-02 11:56:28 -05:00
parent f63e052ccd
commit 0fe8914981
4 changed files with 40 additions and 3 deletions

View File

@@ -121,7 +121,35 @@
document.addEventListener('submit', event => {
if (relevant(event.target)) { enhance(event.target); sync(event.target); }
}, true);
// Preserve the vendor export buttons and download behavior while adding CSRF protection.
// Submit exports as a normal download. This avoids the vendor AJAX/Blob flow,
// which silently fails on browsers that block downloads from async callbacks.
document.addEventListener('click', event => {
const button = event.target.closest?.('#export-leads, #export-inquiries');
if (!button) return;
event.preventDefault();
event.stopImmediatePropagation();
if (!config.ajaxUrl || !config.exportNonce) {
window.alert('Please sign in again before exporting.');
return;
}
const form = document.createElement('form');
form.method = 'POST';
form.action = config.ajaxUrl;
form.style.display = 'none';
const action = document.createElement('input');
action.type = 'hidden';
action.name = 'action';
action.value = button.id === 'export-leads' ? 'houzez_crm_export_leads' : 'crm_export_inquiries';
const nonce = document.createElement('input');
nonce.type = 'hidden';
nonce.name = 'jenhome_export_nonce';
nonce.value = config.exportNonce;
form.append(action, nonce);
document.body.append(form);
form.submit();
window.setTimeout(() => form.remove(), 1000);
}, true);
// Keep the nonce attached if another Houzez view calls these endpoints by AJAX.
$.ajaxPrefilter(function (options) {
const url = new URL(options.url, location.href);
if (url.origin !== location.origin || !url.pathname.endsWith('/admin-ajax.php')) return;