Problem/Motivation

This relates to webforms with a scheduled closing date, where the form is loaded (or a draft resumed) shortly before the cutoff point, but submitted after it.

Non-AJAX form: behaves as expected: on submission you receive a "Sorry…This form is closed to new submissions." message.

(Minor point, I'd argue form_open_message and form_close_message should be shown as errors (red) rather than success (green), but I'm struggling to find where that code actually is in the module.)

AJAX enabled form: if you load the form before the closing time but submit afterwards, the XHR produces an internal server error - specifically it throws the exception in core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php:67 about the AJAX callback being empty.

Having just done remote Xdebug on that, in the preceding code, $form_state->getTriggeringElement() returns null, and thus $callback is null.
(I appreciate that alone may not be very useful.)

Proposed resolution

Comments

wturrell created an issue. See original summary.

jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new981 bytes

Wow, I initially thought I could not solve this problem but I think I figured out the solution.

The attached patch hides the submit buttons using '#access': FALSE instead of completely removing them. Please review the attached patch.

Status: Needs review » Needs work

The last submitted patch, 2: 3025554-2.patch, failed testing. View results

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new3.62 KB
jrockowitz’s picture

My patch does not seem to be fixing this issue.

Below is the exact error message.

ResponseText: The website encountered an unexpected error. Please try again later.Symfony\Component\HttpKernel\Exception\HttpException: The specified #ajax callback is empty or not callable. in Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse() (line 67 of core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php). Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber->onException(Object, 'kernel.exception', Object)

wturrell’s picture

Yes, error unchanged with patch for me also.

jrockowitz’s picture

Yep, I am going to have look at exactly what is throwing the error. I really afraid to think that the form's current state/token is lost when a webform is automatically closed.

jrockowitz’s picture

StatusFileSize
new1.88 KB

The attached patch prevents the fatal error and instead displays an alert stating "Unable to complete the request. Please reload the current page."

jrockowitz’s picture

So I have run into #2352009: Bubbling of elements' max-age to the page's headers and the page cache when testing this issue because the cached anonymous form is not being updated to display the closed message after the form is closed.

jrockowitz’s picture

StatusFileSize
new3.87 KB

This patch begins to address the caching issue.

jrockowitz’s picture

StatusFileSize
new6.55 KB
new162.1 KB

The attached patch displays the below confirm dialog and then reloads the page.

jrockowitz’s picture

Manual test script

  • Create a new Webform with Ajax enabled.
  • Open webform in an incognito tab
  • Close the Webform manually or schedule the form to close in 1 minute
  • Try to submit webform (after it has closed) in the incognito tab

  • jrockowitz authored 2f807fb on 8.x-5.x
    Issue #3025554 by jrockowitz: Submitting AJAX form after closing date...
jrockowitz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.