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

Created on 23 May 2024, 7 months ago
Updated 1 August 2024, 5 months 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

Fixed

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

Merge Requests

Comments & Activities

  • Issue created by @chrisolof
  • Status changed to Needs review 7 months ago
  • Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 8
    last update 7 months 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
  • First commit to issue fork.
  • Pipeline finished with Skipped
    5 months ago
    #228189
    • vaish β†’ committed 22b0708a on 2.0.x
      Issue #3449508 by vaish, chrisolof: Undefined array key "extension" in /...
  • Status changed to Fixed 5 months ago
  • πŸ‡·πŸ‡ΈSerbia vaish
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024