From 0fe8914981d0eacdef1993148c8b73870e11cf56 Mon Sep 17 00:00:00 2001 From: josh Date: Mon, 2 Nov 2026 11:56:28 -0500 Subject: [PATCH] Make CRM exports download reliably --- CHANGELOG.md | 5 +++++ README.md | 3 +++ forms.js | 30 +++++++++++++++++++++++++++++- jenhome-contact-exports.php | 5 +++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f03c887..0d737a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.4.0 + +- Make Leads and Inquiries export buttons submit a normal authenticated CSV download instead of relying on asynchronous AJAX/Blob downloads. +- Keep the established 24-column Leads and eight-column Inquiries layouts. + ## 1.3.0 - Enable the plugin on the approved Jen Home production site as well as staging. diff --git a/README.md b/README.md index 96d7f77..56569cd 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ omit Source Link and retain their other existing fields. CRM views still show in though the shorter Inquiries CSV omits them. Historical records are not backfilled or split; relationships use IDs, never email matching. +The CRM export buttons submit the protected endpoints as normal browser downloads, +so the CSV is not dependent on an asynchronous JavaScript Blob download. + The plugin creates a prefixed `jenhome_contact_fields` extension table for middle names and exact submission provenance. Native Houzez tables and vendor files are not modified. Keep this table when rolling back or deactivating the plugin. diff --git a/forms.js b/forms.js index 09b0939..699060b 100644 --- a/forms.js +++ b/forms.js @@ -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; diff --git a/jenhome-contact-exports.php b/jenhome-contact-exports.php index 8b01989..9716de8 100644 --- a/jenhome-contact-exports.php +++ b/jenhome-contact-exports.php @@ -4,7 +4,7 @@ * Plugin URI: https://hostlabs.pro/ * Update URI: https://git.labs.casa/josh/jenhomeforms * Description: Jen Home Houzez contact fields, inquiry ownership and protected CSV exports. - * Version: 1.3.0 + * Version: 1.4.0 * Requires at least: 6.2 * Requires PHP: 8.1 * Author: Josh Stevens Sr @@ -13,7 +13,7 @@ defined('ABSPATH') || exit; final class Jenhome_Contact_Exports { - const VERSION = '1.3.0'; + const VERSION = '1.4.0'; const INQUIRY_OWNER_ID = 7; const ACTIONS = ['houzez_ele_inquiry_form', 'houzez_ele_contact_form', 'houzez_property_agent_contact', 'houzez_schedule_send_message', 'houzez_contact_realtor']; // Verified Elementor widgets: contact page and the two Get Started popups. @@ -80,6 +80,7 @@ final class Jenhome_Contact_Exports { wp_localize_script('jenhome-contact-exports', 'JenhomeContact', [ 'actions' => self::ACTIONS, 'referralForms' => self::REFERRAL_FORMS, 'referrals' => self::referrals(), 'nonce' => wp_create_nonce('jenhome_contact'), + 'ajaxUrl' => admin_url('admin-ajax.php'), 'exportNonce' => is_user_logged_in() ? wp_create_nonce('jenhome_export') : '', ]); wp_register_style('jenhome-contact-exports', false, [], self::VERSION);