From c46f87cffafb491753168cc5f1ba9da0c8b0a825 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 3 Sep 2014 11:49:26 +0100 Subject: [PATCH] CRM-15225 - Fix handling of chainSelect on billing forms --- CRM/Core/Form.php | 3 ++- CRM/Core/Payment/Form.php | 52 ++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 19cfe82493..837eba3e38 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1750,7 +1750,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $this->_chainSelectFields[$settings['control_field']] = $elementName; - return $this->add('select', $elementName, $settings['label'], array(), $settings['required'], $props); + return $this->add('select', $elementName, $settings['label'], NULL, $settings['required'], $props); } /** @@ -1783,6 +1783,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $options = array('' => $targetField->getAttribute('placeholder')) + $options; $targetField->removeAttribute('placeholder'); } + $targetField->_options = array(); $targetField->loadArray($options); } } diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index b6b72db8b3..3725d82283 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -137,7 +137,7 @@ class CRM_Core_Payment_Form { /** * create all fields needed for a credit card transaction * - * @param $form + * @param CRM_Core_Form $form * * @return void * @access public @@ -187,6 +187,27 @@ class CRM_Core_Payment_Form { ); } + /** + * @param CRM_Core_Form $form + */ + static function addCommonFields(&$form, $useRequired) { + foreach ($form->_paymentFields as $name => $field) { + if (!empty($field['cc_field'])) { + if ($field['htmlType'] == 'chainSelect') { + $form->addChainSelect($field['name'], array('required' => $useRequired && $field['is_required'])); + } + else { + $form->add($field['htmlType'], + $field['name'], + $field['title'], + $field['attributes'], + $useRequired ? $field['is_required'] : FALSE + ); + } + } + } + } + /** * create all fields needed for direct debit transaction * @@ -249,21 +270,7 @@ class CRM_Core_Payment_Form { static function buildCreditCard(&$form, $useRequired = FALSE) { if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) { self::setCreditCardFields($form); - foreach ($form->_paymentFields as $name => $field) { - if (!empty($field['cc_field'])) { - if ($field['htmlType'] == 'chainSelect') { - $form->addChainSelect($field['name'], array('required' => $useRequired && $field['is_required'])); - } - else { - $form->add($field['htmlType'], - $field['name'], - $field['title'], - $field['attributes'], - $useRequired ? $field['is_required'] : FALSE - ); - } - } - } + self::addCommonFields($form, $useRequired); $form->addRule('cvv2', ts('Please enter a valid value for your card security code. This is usually the last 3-4 digits on the card\'s signature panel.'), @@ -317,18 +324,7 @@ class CRM_Core_Payment_Form { static function buildDirectDebit(&$form, $useRequired = FALSE) { if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) { self::setDirectDebitFields($form); - foreach ($form->_paymentFields as $name => $field) { - if (isset($field['cc_field']) && - $field['cc_field'] - ) { - $form->add($field['htmlType'], - $field['name'], - $field['title'], - $field['attributes'], - $useRequired ? $field['is_required'] : FALSE - ); - } - } + self::addCommonFields($form, $useRequired); $form->addRule('bank_identification_number', ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'), -- 2.25.1