diff --git a/formscrm.php b/formscrm.php index 5f91a1c..91f5192 100644 --- a/formscrm.php +++ b/formscrm.php @@ -3,7 +3,7 @@ * Plugin Name: FormsCRM * Plugin URI : https://close.technology/wordpress-plugins/formscrm/ * Description: Connects Forms with CRM, ERP and Email Marketing. - * Version: 4.2.1 + * Version: 4.2.2-beta.1 * Author: CloseTechnology * Author URI: https://close.technology * Text Domain: formscrm @@ -23,7 +23,7 @@ defined( 'ABSPATH' ) || die( 'No script kiddies please!' ); -define( 'FORMSCRM_VERSION', '4.2.1' ); +define( 'FORMSCRM_VERSION', '4.2.2-beta.1' ); define( 'FORMSCRM_PLUGIN', __FILE__ ); define( 'FORMSCRM_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'FORMSCRM_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); diff --git a/includes/assets/formscrm-admin.css b/includes/assets/formscrm-admin.css index 89c6ad9..186abef 100644 --- a/includes/assets/formscrm-admin.css +++ b/includes/assets/formscrm-admin.css @@ -554,3 +554,32 @@ width: 1.5rem; height: 1.5rem; } + +/* Contact Form 7 Auto-Submit Styles */ +@keyframes formscrm-rotation { + from { + transform: rotate(0deg); + } + to { + transform: rotate(359deg); + } +} + +.formscrm-saving-indicator { + display: inline-flex; + align-items: center; + font-size: 14px; + margin-left: 10px; + color: #46b450; +} + +.formscrm-saving-indicator .dashicons { + margin-right: 5px; + animation: formscrm-rotation 1s infinite linear; +} + +.formscrm-submitting { + opacity: 0.6; + pointer-events: none; + cursor: wait; +} diff --git a/includes/assets/js/cf7-autosubmit.js b/includes/assets/js/cf7-autosubmit.js new file mode 100644 index 0000000..6dbe3aa --- /dev/null +++ b/includes/assets/js/cf7-autosubmit.js @@ -0,0 +1,99 @@ +/** + * Contact Form 7 Auto-Submit Script + * + * @package FormsCRM + * @version 4.2.2 + */ + +(function() { + 'use strict'; + + // Wait for DOM to be ready. + if ( document.readyState === 'loading' ) { + document.addEventListener( 'DOMContentLoaded', initAutoSubmit ); + } else { + initAutoSubmit(); + } + + /** + * Initialize auto-submit functionality + * + * @return void + */ + function initAutoSubmit() { + // Get all select elements with auto-submit attribute. + var autoSubmitSelects = document.querySelectorAll( 'select[data-formscrm-autosubmit="true"]' ); + + if ( ! autoSubmitSelects.length ) { + return; + } + + // Add change event listener to each select. + autoSubmitSelects.forEach( function( select ) { + select.addEventListener( 'change', function( event ) { + handleAutoSubmit( event.target ); + }); + }); + } + + /** + * Handle auto-submit when select changes + * + * @param {HTMLElement} selectElement The select element that changed + * @return void + */ + function handleAutoSubmit( selectElement ) { + // Prevent multiple submissions. + if ( selectElement.dataset.submitting === 'true' ) { + return; + } + + // Find the closest form. + var form = selectElement.closest( 'form' ); + + if ( ! form ) { + console.warn( 'FormsCRM: Could not find parent form for auto-submit' ); + return; + } + + // Mark as submitting to prevent duplicate submissions. + selectElement.dataset.submitting = 'true'; + + // Show saving indicator. + var savingIndicator = selectElement.parentElement.querySelector( '.formscrm-saving-indicator' ); + if ( savingIndicator ) { + savingIndicator.style.display = 'inline-flex'; + } + + // Add visual feedback class. + selectElement.classList.add( 'formscrm-submitting' ); + + // Disable browser "unsaved changes" warning. + disableUnsavedChangesWarning(); + + // Add a small delay to ensure user sees the feedback. + setTimeout( function() { + // Submit the form. + form.submit(); + }, 300 ); + } + + /** + * Disable "unsaved changes" warning + * + * Removes beforeunload event listeners to prevent the browser from + * showing a confirmation dialog when the form is auto-submitted. + * + * @return void + */ + function disableUnsavedChangesWarning() { + // Clear the main beforeunload handler. + window.onbeforeunload = null; + + // Remove jQuery beforeunload handlers (WordPress often uses jQuery). + if ( typeof jQuery !== 'undefined' ) { + jQuery( window ).off( 'beforeunload' ); + } + } +})(); + diff --git a/includes/formscrm-library/class-contactform7.php b/includes/formscrm-library/class-contactform7.php index 14e2468..39cc710 100644 --- a/includes/formscrm-library/class-contactform7.php +++ b/includes/formscrm-library/class-contactform7.php @@ -33,6 +33,7 @@ public function __construct() { add_filter( 'wpcf7_editor_panels', array( $this, 'show_cm_metabox' ) ); add_action( 'wpcf7_after_save', array( $this, 'crm_save_options' ) ); add_action( 'wpcf7_before_send_mail', array( $this, 'crm_process_entry' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_autosubmit_assets' ) ); } /** @@ -61,11 +62,13 @@ public function show_cm_metabox( $panels ) { public function settings_add_crm( $args ) { $cf7_crm_defaults = array(); $cf7_crm = get_option( 'cf7_crm_' . $args->id(), $cf7_crm_defaults ); + $settings_module = isset( $cf7_crm['fc_crm_module'] ) ? $cf7_crm['fc_crm_module'] : ''; ?>