if (!empty($form->_membershipContactID) && $contactID != $form->_membershipContactID) {
// renewal case - membership being renewed may or may not be for organization
if (!empty($form->_employers) && array_key_exists($form->_membershipContactID, $form->_employers)) {
- // if _membershipContactID belongs to employers list, we can say:
+ // if _membershipContactID belongs to employers list, we can say:
$form->_relatedOrganizationFound = TRUE;
}
} else if (!empty($form->_employers)) {
}
$stateCountryMap = array();
+ $location_type_id = null;
foreach ($profileFields as $name => $field) {
if (in_array($field['field_type'], $fieldTypes)) {
list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
}
$stateCountryMap[$index][$prefixName] = 'onbehalf[' . $name . ']';
+
+ if (count($form->_submitValues)) {
+ $location_type_id = $field['location_type_id'];
+ if(!empty($form->_submitValues['onbehalf']["country-{$location_type_id}"]) &&
+ $prefixName == "state_province") {
+ $field['is_required'] = CRM_Core_Payment_Form::checkRequiredStateProvince($form, "country-{$location_type_id}", TRUE);
+ }
+ }
}
elseif (in_array($prefixName, array(
'organization_name', 'email')) &&
CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
$addCaptcha = FALSE;
+ $location_type_id = NULL;
foreach ($fields as $key => $field) {
if ($viewOnly &&
isset($field['data_type']) &&
$stateCountryMap[$index] = array();
}
$stateCountryMap[$index][$prefixName] = $key;
+
+ if ($prefixName == "state_province") {
+ if ($onBehalf) {
+ //CRM-11881: Bypass required-ness check for state/province on Contribution Confirm page
+ //as already done during Contribution registration via onBehalf's quickForm
+ $field['is_required'] = FALSE;
+ }
+ else {
+ if (count($this->_submitValues)) {
+ $location_type_id = $field['location_type_id'];
+ if (array_key_exists("country-{$location_type_id}", $fields) &&
+ array_key_exists("state_province-{$location_type_id}", $fields) &&
+ !empty($this->_submitValues["country-{$location_type_id}"])) {
+ $field['is_required'] =
+ CRM_Core_Payment_Form::checkRequiredStateProvince($this, "country-{$location_type_id}");
+ }
+ }
+ }
+ }
}
if ($onBehalf) {
'attributes' => array(
'' => ts('- select -')) +
CRM_Core_PseudoConstant::stateProvince(),
- 'is_required' => self::checkRequiredStateProvince($form),
+ 'is_required' => self::checkRequiredStateProvince($form, "billing_country_id-{$bltID}"),
);
$form->_paymentFields["billing_postal_code-{$bltID}"] = array(
/**
* function to return state/province is_required = true/false
*
+ * @param obj $form: Form object
+ * @param string $name: Country index name on $_submitValues array
+ * @param bool $onBehalf: Is 'On Behalf Of' profile?
+ *
+ * @return bool
+ * TRUE/FALSE for is_required if country consist/not consist of state/province respectively
+ * @static
*/
- static function checkRequiredStateProvince($form) {
+ static function checkRequiredStateProvince($form, $name, $onBehalf = FALSE) {
// If selected country has possible values for state/province mark the
// state/province field as required.
$config = CRM_Core_Config::singleton();
$stateProvince = new CRM_Core_DAO_StateProvince();
- $stateProvince->country_id = CRM_Utils_Array::value("billing_country_id-{$form->_bltID}", $form->_submitValues);
+
+ if ($onBehalf) {
+ $stateProvince->country_id = CRM_Utils_Array::value($name, $form->_submitValues['onbehalf']);
+ }
+ else {
+ $stateProvince->country_id = CRM_Utils_Array::value($name, $form->_submitValues);
+ }
+
+ $limitCountryId = $stateProvince->country_id;
if ($stateProvince->count() > 0) {
// check that the state/province data is not excluded by a
$limitIds = array_merge($limitIds, array_keys($countryIsoCodes, $code));
}
- $limitCountryId = CRM_Utils_Array::value("billing_country_id-{$form->_bltID}", $form->_submitValues);
if ($limitCountryId && in_array($limitCountryId, $limitIds)) {
return TRUE;
}
return FALSE;
}
+ if (count($this->_submitValues)) {
+ $location_type_id = null;
+ foreach ($this->_fields as $field) {
+ if (!empty($field['location_type_id'])) {
+ $location_type_id = $field['location_type_id'];
+ }
+ if (array_key_exists("country-{$location_type_id}", $this->_fields) &&
+ array_key_exists("state_province-{$location_type_id}", $this->_fields) &&
+ !empty($this->_submitValues["country-{$location_type_id}"])) {
+ $this->_fields["state_province-{$location_type_id}"]['is_required'] =
+ CRM_Core_Payment_Form::checkRequiredStateProvince($this, "country-{$location_type_id}");
+ }
+ }
+ }
+
$this->assign('id', $this->_id);
$this->assign('mode', $this->_mode);
$this->assign('action', $this->_action);