}
/**
+ * 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') {
);
}
}
+ // 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);
}
/**
{/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}