Apparently there are no server side validation of reqired grid component questions on a webform with page breaks.

There are at least two ways to circumvent the HTML5 validation without the user ever tampering with the code.

1) Javascript listeners bound to the submit button can in some instances cause an involuntary jump to the next page (https://www.drupal.org/node/2661154 and https://www.drupal.org/node/2628962).

2) If you edit your webform (add a new component) while it is viewed by a user, and the user revisit the page (by hitting the url again, not reloading with F5), the user is sent to the next page skipping the required fields.

As far as my testing goes, this is only a problem with grids. If you add a required 'Select Options' component, for example, method one above triggers a form_set_error(), and method two brings up the HTML5 validation preventing the user from going further.

Comments

Nicolaj created an issue. See original summary.

nicolaj.knudsen@gmail.com’s picture

I think i've solved the issue, will try to commit a patch shortly.

One more way to reproduce the bug (i.e. skip HTML5 validation):

- View a multipage webform, fill out the first page correctly.
- Go to the next page containing only (required) grid components.
- Go back to the previous page
- Go to the second one more time.
- Reload the page and confirm the resubmit promt.

You will be sent to the third page skipping the required grids.

nicolaj.knudsen@gmail.com’s picture

nicolaj.knudsen@gmail.com’s picture

Priority: Normal » Major

I'm changing the priority to major, since this bug does cause loss of user data.

nicolaj.knudsen@gmail.com’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: webform-missing-grid-validation-2661718.patch, failed testing.

nicolaj.knudsen@gmail.com’s picture

nicolaj.knudsen@gmail.com’s picture

Status: Needs work » Needs review
danchadwick’s picture

Priority: Major » Normal
Status: Needs review » Needs work

There is a bug, but specifically the server only validates that the grid contains at least one answer, rather than all the questions are answered.

The correct fix is to implement webform_validate_grid(). See webform_validate_date() as an example.

To reproduce this for testing purposes, you can comment out the following lines from webform_expand_grid:

      // Add HTML5 required attribute, if needed.
      if ($element['#required']) {
        $element[$key]['#attributes']['required'] = 'required';
      }

  • DanChadwick committed efc082c on 7.x-4.x
    Issue #2661718 by Nicolaj, DanChadwick: Fixed no server side validation...
danchadwick’s picture

Version: 7.x-4.12 » 7.x-4.x-dev
Status: Needs work » Fixed
StatusFileSize
new1.85 KB

Committed to 7.x-4.x.

danchadwick’s picture

Version: 7.x-4.x-dev » 8.x-4.x-dev
Category: Bug report » Task
Status: Fixed » Patch (to be ported)
andreavr’s picture

Version: 8.x-4.x-dev » 7.x-4.14
Status: Patch (to be ported) » Needs work

Hi,

I've been testing a webform using Grid components and general Textfields nested underneath. On updating from 7.x-4.13 -> 7.x-4.14 now my non-required Textfields are treated as required and I'm thinking it's related to this update?

Question 1: Grid required
---Comments: Textfield Not-required

Is this what it's meant to do? If so I'll have to take my Textfield out of the Grid but thought that was the way to format things nicely...

Cheers
Andrea

danchadwick’s picture

Category: Task » Bug report

I agree. Nested components within a required grid should not be required unless they themselves are required. Also, if the entire grid is set as being an error, then all nested components are shown in error highlighting, even if they are not required. Consequently, we have to set each individual question as an error.

  • DanChadwick committed 68ca0cc on 7.x-4.x
    Issue #2661718 by DanChadwick: Provide server grid validation for...
danchadwick’s picture

Status: Needs work » Fixed
StatusFileSize
new1.6 KB

Committed to 7.x-4.x.

danchadwick’s picture

Version: 7.x-4.14 » 8.x-4.x-dev
Category: Bug report » Task
Status: Fixed » Patch (to be ported)

Both patches need up-port to D8.

fenstrat’s picture

Version: 8.x-4.x-dev » 7.x-4.x-dev
Category: Task » Bug report
Status: Patch (to be ported) » Fixed

Closing to clear out the old Webform 8.x-4.x branch. See #2827845: [roadmap] YAML Form 8.x-1.x to Webform 8.x-5.x.

  • DanChadwick committed 68ca0cc on 8.x-5.x
    Issue #2661718 by DanChadwick: Provide server grid validation for...
  • DanChadwick committed efc082c on 8.x-5.x
    Issue #2661718 by Nicolaj, DanChadwick: Fixed no server side validation...

Status: Fixed » Closed (fixed)

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