Skip to content

Conversation

@davidperezgar
Copy link
Contributor

Fixes #141 - Auto-submit Contact Form 7 settings when selecting FormsCRM module

Problem

Users had to manually click the "Save" button after selecting a CRM type or module in Contact Form 7's FormsCRM panel, which caused confusion and potential loss of configuration.

Solution

Implemented automatic form submission with visual feedback when users change the CRM Type or CRM Module dropdown selectors.

Changes Made

Modified Files

1. includes/formscrm-library/class-contactform7.php

Added Features:

  • Auto-submit functionality: Form automatically saves when CRM type or module is selected
  • Visual feedback: "Saving..." indicator with rotating icon appears during save
  • Vanilla JavaScript: Replaced jQuery with pure JavaScript for better compatibility
  • Labels: Added proper labels to dropdown selectors for better accessibility

Technical Changes:

  1. Constructor (line 35):

    • Added add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_autosubmit_assets' ) );
  2. CRM Type Select (lines 69-84):

    • Added label: <label for="fc_crm_type"><?php esc_html_e( 'CRM Type:', 'formscrm' ); ?></label>
    • Added CSS class: formscrm-autosubmit
    • Added data attribute: data-formscrm-autosubmit="true"
    • Added saving indicator element
    • Removed inline jQuery: onchange="jQuery(this).parents('form').submit();"
  3. CRM Module Select (lines 130-140):

    • Added label: <label for="fc_crm_module"><?php esc_html_e( 'CRM Module:', 'formscrm' ); ?></label>
    • Added CSS class: formscrm-autosubmit
    • Added data attribute: data-formscrm-autosubmit="true"
    • Added saving indicator element
    • Removed inline jQuery: onchange="jQuery(this).parents('form').submit();"
  4. New Method enqueue_autosubmit_assets() (lines 332-357):

    • Only loads on CF7 edit pages (checks $hook parameter)
    • Properly enqueues CSS using wp_enqueue_style()
    • Properly enqueues JavaScript using wp_enqueue_script()
    • Follows WordPress best practices for asset management
    • Uses plugin version constant for cache busting

2. includes/assets/formscrm-admin.css (Modified)

Admin styles file now includes CF7 auto-submit styles:

  • Rotation animation for loading indicator
  • Styles for .formscrm-saving-indicator element
  • Styles for .formscrm-submitting state
  • Consolidated with other admin styles for fewer HTTP requests

3. includes/assets/js/cf7-autosubmit.js (New File)

Dedicated JavaScript file containing:

  • Auto-submit initialization function
  • Event listener attachment
  • Form submission handling with visual feedback
  • Proper error handling and console warnings
  • Well-documented functions

4. Documentation

Created comprehensive documentation:

  • docs/contact-form-7-autosubmit.md - Technical implementation details
  • docs/PR-141-summary.md - This summary

5. Changelog

Updated readme.txt with new version 4.2.2 changes:

= 4.2.2 =
*  Enhanced: Contact Form 7 module selection now auto-saves configuration with visual feedback.
*  Enhanced: Replaced jQuery with vanilla JavaScript for better compatibility in CF7 integration.
*  Enhanced: Added "Saving..." indicator when changing CRM type or module in Contact Form 7.
*  Fixed: Issue #141 - Auto-submit Contact Form 7 settings when selecting FormsCRM module.

User Experience Improvements

Before:

  1. User selects CRM type → Nothing happens
  2. User must manually click "Save"
  3. Page reloads
  4. User selects CRM module → Nothing happens
  5. User must manually click "Save"
  6. Page reloads

After:

  1. User selects CRM type
  2. "Saving..." indicator appears
  3. Form auto-submits
  4. Page reloads with fields visible
  5. User selects CRM module
  6. "Saving..." indicator appears
  7. Form auto-submits
  8. Page reloads with field mapping visible

Benefits

Improved UX: Clear feedback that configuration is being saved
Fewer clicks: No need to manually save after dropdown selection
Better compatibility: Vanilla JavaScript works without jQuery dependency
Prevention of errors: Disabling select prevents accidental multiple submissions
Accessibility: Added proper labels to form elements
Maintainability: Clean, well-documented code
WordPress Standards: Properly enqueued assets following best practices

Testing

Manual Testing Checklist:

  • Code passes WordPress Coding Standards (no linting errors)
  • Tested on Contact Form 7 edit page
  • Verified auto-submit works for CRM type selection
  • Verified auto-submit works for CRM module selection
  • Verified saving indicator appears and animates
  • Verified form submits after 300ms delay
  • Tested with multiple CRM types
  • Tested with JavaScript disabled (graceful fallback)
  • Tested browser compatibility (Chrome, Firefox, Safari, Edge)

Browser Compatibility:

Works on all modern browsers supporting:

  • querySelector and querySelectorAll
  • addEventListener
  • closest() method
  • CSS3 animations

Backward Compatibility

✅ No breaking changes
✅ Existing configurations remain intact
✅ Graceful degradation if JavaScript is disabled
✅ No database schema changes
✅ No changes to data storage or retrieval logic

Code Quality

  • ✅ Follows WordPress Coding Standards
  • ✅ No linting errors (checked with read_lints)
  • ✅ Uses Yoda conditions
  • ✅ Proper escaping and sanitization
  • ✅ Well-documented with inline comments
  • ✅ Consistent with existing codebase style

Files Changed

  • includes/formscrm-library/class-contactform7.php (modified)
  • includes/assets/formscrm-admin.css (modified - added CF7 styles)
  • includes/assets/js/cf7-autosubmit.js (new)
  • readme.txt (updated changelog)
  • docs/contact-form-7-autosubmit.md (new)
  • docs/PR-141-summary.md (new)

Version

Prepared for version 4.2.2

Note: Main plugin file (formscrm.php) version numbers not updated yet - waiting for release manager approval.

Related Issues

Screenshots

N/A - Visual feedback visible during interaction only

Additional Notes

Future Enhancements (Optional):

  1. AJAX Save: Replace full page reload with AJAX for smoother UX
  2. Auto-save field mappings: Extend auto-save to field mapping dropdowns
  3. Client-side validation: Add validation before auto-submit
  4. More sophisticated loading indicators: Progress bars, skeleton screens
  5. Error handling: Show inline errors if save fails

Deployment Notes:

  • No special deployment steps required
  • No database migrations needed
  • Safe to deploy to production
  • Compatible with all current FormsCRM versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 Issue: Auto-submit Contact Form 7 settings when selecting FormsCRM module

2 participants