Undefined array key "extension" in /src/Element/PhoneNumber.php on line 237

Created on 23 May 2024, about 1 month ago
Updated 24 May 2024, about 1 month ago

Problem/Motivation

In some environments I'm running into this error, with or without an ext. entry, when submitting into an ajax-enabled webform.

Steps to reproduce

1. Set up a multi-page, ajax-enabled webform with a full phone number field (including extension) on an early page.
2. Fill the phone number field and proceed to the next page of the webform.
3. Hit the error (see in console - form is submitting via ajax).

I am only able to reproduce this in certain environments, while logged into the website. Exactly why remains unknown currently.

Proposed resolution

Harden and improve code that validates and saves form submissions.

Remaining tasks

Review.

User interface changes

Client-side validation of the extension sub-field.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States chrisolof

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @chrisolof
  • Status changed to Needs review about 1 month ago
  • Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 8
    last update about 1 month ago
    Waiting for branch to pass
  • πŸ‡ΊπŸ‡ΈUnited States chrisolof

    The attached patch resolves the issue in the affected environments.

    I've made three changes in here:

    1. Switch the extension sub-field type from text to numeric.
    2. Remove the custom numeric extension validation code in Drupal\phone_number\Element\PhoneNumber::phoneNumberValidate() that is no longer needed.
    3. Ensure the array key "extension" is actually set before trying to access its value in Drupal\phone_number\Element\PhoneNumber::phoneNumberValidate().

    I suspect the third change is most responsible for eliminating the error here, and the patch could certainly be reduced to just that change. However while examining the validation of our extension sub-field it felt like a good opportunity to correct its field type and reduce our element's validation code a little bit. It could be this validation area was written before core had a numeric field type, or perhaps the original author was unaware of it. At any rate, this also enables client-side validation of the extension field, which is nice and something we've never had.

  • πŸ‡ΊπŸ‡ΈUnited States chrisolof
Production build 0.69.0 2024