Problem/Motivation

uswds_preprocess_form_element() does not properly check for the existence of a form element's id key before trying to access it.

Steps to reproduce

  1. Install the webform module
  2. Create a webform
  3. Add a text field with a maximum word length
  4. Save and browse to the form
  5. Attempt to submit the form with a value that exceeds the maximum word length

Expected: A validation message appears
Actual: A validation message appears, but also you get:

Warning: Undefined array key "id" in uswds_preprocess_form_element() (line 32 of themes/contrib/uswds/preprocess/element/form_element.preprocess.inc).

Proposed resolution

The line in question is:

$variables['error_id'] = $variables['element']['#attributes']['id']; But as far as I can tell the error_id value is never used. I believe the correct solution is to simply remove this line.

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

CommentFileSizeAuthor
#2 undefined_array_key_id-3327730-2.patch501 bytesjoshf

Comments

joshf created an issue. See original summary.

joshf’s picture

StatusFileSize
new501 bytes

This patch removes the erroring line entirely. If it turns out this is actually used for something, we should probably just add a default to NULL.

joshf’s picture

Assigned: joshf » Unassigned
Status: Active » Needs review
joshf’s picture

Status: Needs review » Closed (outdated)

Turns out this is actually fixed in the latest dev.