Error message: Warning: Invalid argument supplied for foreach() in /core/lib/Drupal/Core/Form/FormState.php on line 1112

Steps to reproduce:
1. Log in with an existing user (works as per usual using the 8.x-1.0-rc2 build)
2. Added some items and checkout
3. Enter a new 3D secure payment card and attempt to pay with it
4. The above exception is thrown. Full log attached.

Commerce: 2.14

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

vanlindholm created an issue. See original summary.

mglaman’s picture

Status: Active » Postponed (maintainer needs more info)

Can you provide the testing card number you used? We have tests covering this and I want to see how we can improve them. Do you have Commerce 2.14?

Unfortunately, the log shows the problem is in an empty #parents array. That makes it really hard to troubleshoot as we don't know what is causing there to be an empty array.

Have you been able to reproduce locally or help provide debugging?

carsteng’s picture

Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new629.11 KB

I get a similar bug:

The same steps to reproduce but I have used a real credit card in test mode.
The API answers with: Your card was declined. Your request was in test mode, but used a non test (live) card. For a list of valid test cards, visit: https://stripe.com/docs/testing.
Therefore in doCreatePaymentMethod() the Exception is raised.

Apperently there is an issue with the address form element. Check the image.

Notice: Undefined index: #parents in Drupal\Core\Form\FormElementHelper::getElementByName() (Zeile 26 in /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormElementHelper.php) #0 /var/www/pattydoo/docroot/core/includes/bootstrap.inc(587): _drupal_error_handler_real(8, 'Undefined index...', '/var/www/pattyd...', 26, Array) #1 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormElementHelper.php(26): _drupal_error_handler(8, 'Undefined index...', '/var/www/pattyd...', 26, Array) #2 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormElementHelper.php(29): Drupal\Core\Form\FormElementHelper::getElementByName('payment_informa...', Array) #3 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormElementHelper.php(29): Drupal\Core\Form\FormElementHelper::getElementByName('payment_informa...', Array) #4 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormElementHelper.php(29): Drupal\Core\Form\FormElementHelper::getElementByName('payment_informa...', Array) #5 /var/www/pattydoo/docroot/core/modules/inline_form_errors/src/FormErrorHandler.php(81): Drupal\Core\Form\FormElementHelper::getElementByName('payment_informa...', Array) #6 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormErrorHandler.php(23): Drupal\inline_form_errors\FormErrorHandler->displayErrorMessages(Array, Object(Drupal\Core\Form\FormState)) #7 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormValidator.php(201): Drupal\Core\Form\FormErrorHandler->handleFormErrors(Array, Object(Drupal\Core\Form\FormState)) #8 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormValidator.php(119): Drupal\Core\Form\FormValidator->finalizeValidation(Array, Object(Drupal\Core\Form\FormState), 'commerce_checko...') #9 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(576): Drupal\Core\Form\FormValidator->validateForm('commerce_checko...', Array, Object(Drupal\Core\Form\FormState)) #10 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(319): Drupal\Core\Form\FormBuilder->processForm('commerce_checko...', Array, Object(Drupal\Core\Form\FormState)) #11 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(217): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\MultistepDefault), Object(Drupal\Core\Form\FormState)) #12 /var/www/pattydoo/docroot/modules/contrib/commerce/modules/checkout/src/Controller/CheckoutController.php(94): Drupal\Core\Form\FormBuilder->getForm(Object(Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\MultistepDefault), 'order_informati...') #13 [internal function]: Drupal\commerce_checkout\Controller\CheckoutController->formPage(Object(Drupal\Core\Routing\RouteMatch)) #14 /var/www/pattydoo/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #15 /var/www/pattydoo/docroot/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #16 /var/www/pattydoo/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #17 /var/www/pattydoo/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #18 /var/www/pattydoo/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #19 /var/www/pattydoo/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #20 /var/www/pattydoo/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /var/www/pattydoo/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /var/www/pattydoo/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #23 /var/www/pattydoo/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #24 /var/www/pattydoo/docroot/modules/contrib/shield/src/ShieldMiddleware.php(115): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /var/www/pattydoo/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\shield\ShieldMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 /var/www/pattydoo/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 /var/www/pattydoo/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #28 /var/www/pattydoo/docroot/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #29 /var/www/pattydoo/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #30 {main}.
vanlindholm’s picture

Hi Matt,

I used commerce 2.14 and the 4000000000003220 testing card.

Thanks,
Thomas

Primsi made their first commit to this issue’s fork.

primsi’s picture

Status: Active » Needs review

I opened a MR. This fixes the issue for us, but I am not sure if that's the optimal approach.

jonathanshaw’s picture

Status: Needs review » Closed (duplicate)

This is a duplicate of #3177168: line 1112 of /app/web/core/lib/Drupal/Core/Form/FormState.php when postal code validation fails (although the patch here is perhaps slightly better).