Checkout crashes if there's a form validation error and no administrative area is set in the address

Created on 28 October 2023, about 1 year ago
Updated 8 July 2024, 6 months ago

Problem/Motivation

Not all countries have an administrative area (e.g., State or Province). A critical error occurs during checkout if the address field for the administrative area is not set, and there is any other error during form validation.

The website encountered an unexpected error. Please try again later.
TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in implode() (line 26 of core/lib/Drupal/Core/Form/FormElementHelper.php).

implode('][', NULL) (Line: 26)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 29)
Drupal\Core\Form\FormElementHelper::getElementByName('payment_information][add_payment_method][billing_information][copy_fields][tax_number][0', Array) (Line: 81)
Drupal\inline_form_errors\FormErrorHandler->displayErrorMessages(Array, Object) (Line: 23)
Drupal\Core\Form\FormErrorHandler->handleFormErrors(Array, Object) (Line: 199)
Drupal\Core\Form\FormValidator->finalizeValidation(Array, Object, 'commerce_checkout_flow_multistep_default') (Line: 119)
Drupal\Core\Form\FormValidator->validateForm('commerce_checkout_flow_multistep_default', Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('commerce_checkout_flow_multistep_default', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 224)
Drupal\Core\Form\FormBuilder->getForm(Object, 'order_information') (Line: 143)
Drupal\commerce_checkout\Controller\CheckoutController->formPage(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  1. Proceed to checkout, selecting a country without an administrative area (e.g., Portugal).
  2. Choose "Stripe" as the payment method.
  3. Enter an invalid VAT number in the "Tax number" field.
  4. Upon submission, the site crashes.

Proposed resolution

Validate if $element['address']['widget'][0]['address'] is set.

πŸ› Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

πŸ‡΅πŸ‡ΉPortugal introfini

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

Comments & Activities

Production build 0.71.5 2024