$form->addElement('text', 'member_source', ts('Source'));
CRM_Core_Form_Date::buildDateRange($form, 'member_join_date', 1, '_low', '_high', ts('From'), FALSE);
+ $form->addElement('hidden', 'member_join_date_range_error');
CRM_Core_Form_Date::buildDateRange($form, 'member_start_date', 1, '_low', '_high', ts('From'), FALSE);
+ $form->addElement('hidden', 'member_start_date_range_error');
CRM_Core_Form_Date::buildDateRange($form, 'member_end_date', 1, '_low', '_high', ts('From'), FALSE);
+ $form->addElement('hidden', 'member_end_date_range_error');
+
+ $form->addFormRule(array('CRM_Member_BAO_Query', 'formRule'), $form);
$form->addYesNo('member_is_primary', ts('Primary Member?'), TRUE);
$form->addYesNo('member_pay_later', ts('Pay Later?'), TRUE);
}
}
+ /**
+ * Check if the values in the date range are in correct chronological order.
+ * @todo Find a better way to implement this validation when multiple date ranges are present.
+ *
+ * @param array $fields
+ * @param array $files
+ * @param CRM_Core_Form $form
+ *
+ * @return bool|array
+ */
+ public static function formRule($fields, $files, $form) {
+ $errors = array();
+
+ if ((empty($fields['member_join_date_low']) || empty($fields['member_join_date_high'])) && (empty($fields['member_start_date_low']) || empty($fields['member_start_date_high'])) && (empty($fields['member_end_date_low']) || empty($fields['member_end_date_high']))) {
+ return TRUE;
+ }
+ $lowDate = strtotime($fields['member_join_date_low']);
+ $highDate = strtotime($fields['member_join_date_high']);
+
+ if ($lowDate > $highDate) {
+ $errors['member_join_date_range_error'] = ts('Please check that your Member Since Date Range is in correct chronological order.');
+ }
+
+ $lowDate1 = strtotime($fields['member_start_date_low']);
+ $highDate1 = strtotime($fields['member_start_date_high']);
+ if ($lowDate1 > $highDate1) {
+ $errors['member_start_date_range_error'] = ts('Please check that your Start Date Range is in correct chronological order.');
+ }
+
+ $lowDate2 = strtotime($fields['member_end_date_low']);
+ $highDate2 = strtotime($fields['member_end_date_high']);
+ if ($lowDate2 > $highDate2) {
+ $errors['member_end_date_range_error'] = ts('Please check that your End Date Range is in correct chronological order.');
+ }
+
+ return empty($errors) ? TRUE : $errors;
+ }
}