Skip to content

Plugin adoption#28

Open
wotis wants to merge 3 commits into
bgermann:masterfrom
wotis:fix-ajax-multiple-forms
Open

Plugin adoption#28
wotis wants to merge 3 commits into
bgermann:masterfrom
wotis:fix-ajax-multiple-forms

Conversation

@wotis
Copy link
Copy Markdown

@wotis wotis commented Jan 19, 2026

This PR is for handling the plugin adoption. The original submission had some more stuff:

  • Time handling fixes that were already dealt with differently. These are dropped.
  • Two new libraries (almost unused so I do not see the point) with security and i18n stuff. This is completely artificial and I suggest not to make these changes. However, I have rebased them on top of this PR at branch refactoring/security-i18n.

New Features

New CSS styles.
A Gutenberg block that I could not get to work. This will need more changes. However, it does not harm the current functions, so I have taken this as well.

Problem Description

When using two forms via shortcode on the same page, AJAX submission can fail or hang at the "waiting" message. This issue is particularly evident when the first form is hidden due to time/date constraints while the second form is visible and being submitted.

Steps to Reproduce

  1. Create two forms (e.g., with IDs 51 and 52)
  2. Add both to a page using shortcodes: [cforms]51[/cforms] and [cforms]52[/cforms]
  3. Configure first form with date/time restrictions so it's not displayed
  4. Try to submit the second form via AJAX
  5. Observe that the "waiting" message does not disappear

Root Cause

  1. Orphaned HTML elements: Forms hidden by time constraints still create HTML message box elements (<div id="usermessage...a">) even though the form itself is not rendered
  2. Missing AJAX error handling: No error handling for invalid responses or AJAX failures
  3. JSON corruption: Additional output can corrupt JSON responses from the server

Changes Made

In lib_render.php (lines 116-123)

  • Move cforms2_check_time() check before creating any HTML elements
  • Prevents orphaned message boxes for forms that won't be displayed
  • Remove duplicate time check logic later in the file

In lib_ajax.php (lines 20-23)

  • Add ob_clean() to clear any previous output before sending JSON
  • Ensures clean JSON responses without corrupted data

In js/cforms.js (lines 185-202)

  • Replace jQuery.post() with jQuery.ajax() for better error handling
  • Add response validation to check for valid JSON structure
  • Add error handler for AJAX failures
  • Use configured failure messages instead of technical error output

Impact

This fix ensures that:

  • Multiple forms can coexist on the same page
  • Time-restricted forms don't interfere with other forms
  • AJAX errors are handled gracefully
  • Users see configured error messages, not technical output
  • Form submissions are reliable even under load

Wolfgang Tischer and others added 3 commits May 15, 2026 11:35
When two forms are present on a page (especially when one is hidden due
to time constraints), AJAX submissions could hang at "waiting" message.

Changes:
- Move time constraint check before HTML element creation to prevent
  orphaned message boxes for hidden forms
- Add robust AJAX error handling with response validation
- Use configured failure messages instead of technical error output
- Clear output buffer before JSON response to prevent parsing errors

Fixes issue where second form's AJAX submission would not complete when
first form was present but hidden by date/time restrictions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
MODERN ADMIN INTERFACE:
- Responsive design for mobile devices
- Modern CSS styles (admin-modern.css)
- Mobile optimized admin interface

GUTENBERG INTEGRATION:
- Complete block editor support
- New blocks/ directory
- Modern WordPress integration
- Extended block features (lib_blocks.php)

MOBILE RESPONSIVE:
- Mobile admin CSS (mobile-admin.css)
- Responsive design (mobile-responsive.css)
- Touch-optimimized operation
@bgermann bgermann force-pushed the fix-ajax-multiple-forms branch from 9798022 to aac4c2a Compare May 15, 2026 11:02
@bgermann bgermann changed the title Fix AJAX submission issues with multiple forms on same page Plugin adoption May 15, 2026
@bgermann
Copy link
Copy Markdown
Owner

Hi @wotis. Wenn du möchtest, können wir die Plugin-Übergabe mit diesem PR koordinieren. Ich habe einen Teil der Änderungen hier gelassen und einige in einen neuen Branch geschoben. Wir können den Stand dieses PRs per SVN in das WordPress-Repository hochladen. Du checkst es aus mit:

svn checkout https://plugins.svn.wordpress.org/cforms2/trunk cforms2

Wenn ich ein Version 16.0.0 veröffentlichen möchte, dann mache ich folgende Schritte in dem dann erstellten Verzeichnis:

# Alle Dateien vom Server aktualisieren
svn update

# Alle Dateien kopieren. Die Änderungen zeigst du an mit:
svn stat

svn commit -m "import version 16.0.0"
svn copy -m "tag version 16.0.0" https://plugins.svn.wordpress.org/cforms2/trunk https://plugins.svn.wordpress.org/cforms2/tags/16.0.0

Das letzte Kommando taggt das Release. Ich würde den Stable tag (in readme.txt) immer auf trunk zeigen lassen, dann brauchst du ihn nicht immer beim Release ändern. Wenn du allerdings im SVN nicht release-fähige Änderungen machen möchtest, dann solltest du den Stable tag setzen, um nicht auf die aktuelle Version zeigen zu lassen.

Wenn du das Plugin weiter in GitHub entwickeln willst, dann lösche bitte die existierenden Tags und tagge diesen Stand als 16.0.0. Die weiteren Änderungen kannst du dann so machen wie du möchtest.

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.

2 participants