$highDate = strtotime($fields['contribution_date_high']);
if ($lowDate > $highDate) {
-
$errors['contribution_date_range_error'] = ts('Please check that your Date Range is in correct chronological order.');
}
return empty($errors) ? TRUE : $errors;
}
CRM_Core_Form_Date::buildDateRange($form, 'mailing_date', 1, '_low', '_high', ts('From'), FALSE);
+ $form->addElement('hidden', 'mailing_date_range_error');
+ $form->addFormRule(array('CRM_Mailing_BAO_Query', 'formRule'), $form);
$mailingJobStatuses = array(
'' => ts('- select -'),
$query->_tables[$tableName] = $query->_whereTables[$tableName] = 1;
}
+ /**
+ * Check if the values in the date range are in correct chronological order.
+ *
+ * @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['mailing_date_high']) || empty($fields['mailing_date_low'])) {
+ return TRUE;
+ }
+ $lowDate = strtotime($fields['mailing_date_low']);
+ $highDate = strtotime($fields['mailing_date_high']);
+
+ if ($lowDate > $highDate) {
+ $errors['mailing_date_range_error'] = ts('Please check that your Date Range is in correct chronological order.');
+ }
+ return empty($errors) ? TRUE : $errors;
+ }
+
}