From 9d42111888f8b9eebeee4e86f733601eb5b51bde Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Mon, 24 Aug 2015 14:07:05 +1200 Subject: [PATCH] CRM-17071 add required marker to payment form 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 | 26 ++++++++++++++++++++++++++ CRM/Core/Payment/ProcessorForm.php | 4 +++- templates/CRM/Core/BillingBlock.tpl | 10 ++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 87e9856ef8..1b674b7ca2 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -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); } /** diff --git a/CRM/Core/Payment/ProcessorForm.php b/CRM/Core/Payment/ProcessorForm.php index 97345f3554..f29b28581c 100644 --- a/CRM/Core/Payment/ProcessorForm.php +++ b/CRM/Core/Payment/ProcessorForm.php @@ -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 diff --git a/templates/CRM/Core/BillingBlock.tpl b/templates/CRM/Core/BillingBlock.tpl index eaf6b908bc..68765b4986 100644 --- a/templates/CRM/Core/BillingBlock.tpl +++ b/templates/CRM/Core/BillingBlock.tpl @@ -35,8 +35,11 @@ {/if}
{foreach from=$paymentFields item=paymentField} + {assign var='name' value=$form.$paymentField.name}
-
{$form.$paymentField.label}
+
{$form.$paymentField.label} + {if $requiredPaymentFields.$name}*{/if} +
{$form.$paymentField.html} {if $paymentField == 'cvv2'}{* @todo move to form assignment*} @@ -59,8 +62,11 @@ {ts}Billing Name and Address{/ts}
{foreach from=$billingDetailsFields item=billingField} + {assign var='name' value=$form.$billingField.name}
-
{$form.$billingField.label}
+
{$form.$billingField.label} + {if $requiredPaymentFields.$name}*{/if} +
{if $form.$billingField.type == 'text'}
{$form.$billingField.html}
{else} -- 2.25.1