From d139d199287f25a24a56c63372376c0643a28ef2 Mon Sep 17 00:00:00 2001 From: Katharina Zwinger Date: Thu, 14 Oct 2021 17:56:43 +0200 Subject: [PATCH] Provide "name" for clientside validation --- braintree_payment.theme.inc | 4 ++++ src/CreditCardForm.php | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/braintree_payment.theme.inc b/braintree_payment.theme.inc index 8efa790..10865db 100644 --- a/braintree_payment.theme.inc +++ b/braintree_payment.theme.inc @@ -21,4 +21,8 @@ function template_process_braintree_payment_hosted_field(array &$vars) { $vars['attributes'] = $element['#attributes'] ?? []; $vars['attributes']['class'] = $element['#wrapper_classes']; $vars['attributes']['data-braintree-hosted-fields-field'] = $element['#field_name']; + $parents = $vars['element']['#parents']; + $name = array_shift($parents); + $name .= $parents ? '[' . implode('][', $parents) . ']' : ''; + $vars['attributes']['name'] = $name; } diff --git a/src/CreditCardForm.php b/src/CreditCardForm.php index 2b47009..d76fd09 100644 --- a/src/CreditCardForm.php +++ b/src/CreditCardForm.php @@ -46,25 +46,21 @@ public function form(array $form, array &$form_state, \Payment $payment) { '#process' => array_merge(['braintree_payment_hosted_fields_process'], element_info('textfield')['#process']), '#field_name' => 'number', '#wrapper_classes' => ['cc-number'], - '#parents' => ['cc-number'], ] + $form['credit_card_number']; $form['secure_code'] = [ '#process' => array_merge(['braintree_payment_hosted_fields_process'], element_info('textfield')['#process']), '#field_name' => 'cvv', '#wrapper_classes' => ['cc-cvv'], - '#parents' => ['cc-cvv'], ] + $form['secure_code']; $form['expiry_date']['month'] = [ '#process' => array_merge(['braintree_payment_hosted_fields_process'], element_info('select')['#process']), '#field_name' => 'expirationMonth', '#wrapper_classes' => ['cc-month'], - '#parents' => ['cc-month'], ] + $form['expiry_date']['month']; $form['expiry_date']['year'] = [ '#process' => array_merge(['braintree_payment_hosted_fields_process'], element_info('select')['#process']), '#field_name' => 'expirationYear', '#wrapper_classes' => ['cc-year'], - '#parents' => ['cc-year'], ] + $form['expiry_date']['year']; // Add extra data.