CRM-17071 add required marker to payment form
authoreileenmcnaugton <eileen@fuzion.co.nz>
Mon, 24 Aug 2015 02:07:05 +0000 (14:07 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Mon, 24 Aug 2015 02:11:11 +0000 (14:11 +1200)
This commit adds the red asterisk to required payment fields, although they
are not set on the form layer as required as we don't want to alter existing validation

CRM/Core/Payment/Form.php
CRM/Core/Payment/ProcessorForm.php
templates/CRM/Core/BillingBlock.tpl

index 87e9856ef8bf27baa64798bb68dfafae2ba12df1..1b674b7ca221e0e4105194b82cc437a2beb906dc 100644 (file)
@@ -187,11 +187,31 @@ class CRM_Core_Payment_Form {
   }
 
   /**
+   * Add the payment fields to the template.
+   *
+   * Generally this is the payment processor fields & the billing fields required
+   * for the payment processor. However, this has been complicated by adding
+   * pay later billing fields into this mix
+   *
+   * We now have the situation where the required fields cannot be set as required
+   * on the form level if they are required for the payment processor, as another
+   * processor might be selected and the validation will then be incorrect.
+   *
+   * However, if they are required for pay later we DO set them on the form level,
+   * presumably assuming they will be required whatever happens.
+   *
+   * As a side-note this seems to re-enforce the argument for making pay later
+   * operate as a payment processor rather than as a 'special thing on its own'.
+   *
    * @param CRM_Core_Form $form
+   *   Form that the payment fields are to be added to.
    * @param bool $useRequired
+   *   Effectively this means are the fields required for pay-later - see above.
    * @param array $paymentFields
+   *   Fields that are to be shown on the payment form.
    */
   protected static function addCommonFields(&$form, $useRequired, $paymentFields) {
+    $requiredPaymentFields = array();
     foreach ($paymentFields as $name => $field) {
       if (!empty($field['cc_field'])) {
         if ($field['htmlType'] == 'chainSelect') {
@@ -206,7 +226,13 @@ class CRM_Core_Payment_Form {
           );
         }
       }
+      // CRM-17071 We seem to be tying ourselves in knots around the addition
+      // of requiring billing fields for pay-later. Here we 'tell' the form the
+      // field is required if it is not otherwise marked as required and is
+      // required for the billing block.
+      $requiredPaymentFields[$field['name']] = !$useRequired ? $field['is_required'] : FALSE;
     }
+    $form->assign('requiredPaymentFields', $requiredPaymentFields);
   }
 
   /**
index 97345f3554d7992d15302908b7c784e0b830f747..f29b28581c85d5da7deb788464c93974939d96f4 100644 (file)
@@ -102,7 +102,9 @@ class CRM_Core_Payment_ProcessorForm {
   }
 
   /**
-   * @param $form
+   * Build the payment processor form.
+   *
+   * @param CRM_Core_Form $form
    */
   public static function buildQuickform(&$form) {
     //@todo document why this addHidden is here
index eaf6b908bcf327357e01f041c97f422c9f4fd91e..68765b49866cda994895c4adde1f8cd94e63b30f 100644 (file)
       {/if}
       <div class="crm-section billing_mode-section {$paymentTypeName}_info-section">
         {foreach from=$paymentFields item=paymentField}
+          {assign var='name' value=$form.$paymentField.name}
           <div class="crm-section {$form.$paymentField.name}-section">
-            <div class="label">{$form.$paymentField.label}</div>
+            <div class="label">{$form.$paymentField.label}
+              {if $requiredPaymentFields.$name}<span class="crm-marker" title="{ts}This field is required.{/ts}">*</span>{/if}
+            </div>
             <div class="content">{$form.$paymentField.html}
               {if $paymentField == 'cvv2'}{* @todo move to form assignment*}
                 <span class="cvv2-icon" title="{ts}Usually the last 3-4 digits in the signature area on the back of the card.{/ts}"> </span>
       <legend>{ts}Billing Name and Address{/ts}</legend>
       <div class="crm-section billing_name_address-section">
         {foreach from=$billingDetailsFields item=billingField}
+          {assign var='name' value=$form.$billingField.name}
           <div class="crm-section {$form.$billingField.name}-section">
-            <div class="label">{$form.$billingField.label}</div>
+            <div class="label">{$form.$billingField.label}
+              {if $requiredPaymentFields.$name}<span class="crm-marker" title="{ts}This field is required.{/ts}">*</span>{/if}
+            </div>
             {if $form.$billingField.type == 'text'}
               <div class="content">{$form.$billingField.html}</div>
             {else}