CRM-15225 - Fix handling of chainSelect on billing forms
authorColeman Watts <coleman@civicrm.org>
Wed, 3 Sep 2014 10:49:26 +0000 (11:49 +0100)
committerColeman Watts <coleman@civicrm.org>
Wed, 3 Sep 2014 10:49:26 +0000 (11:49 +0100)
CRM/Core/Form.php
CRM/Core/Payment/Form.php

index 19cfe82493bb054bf1ddcd4988d344e8e7674ee3..837eba3e38768a4200b64c19ee074f28601fac9d 100644 (file)
@@ -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);
     }
   }
index b6b72db8b39e1b03c18bb3d36006eb0b698d8d6a..3725d82283a740a1bb533a354367ca6c1b78714e 100644 (file)
@@ -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).'),