You are here

function elysia_cron_settings_form_validate in Elysia Cron 7.2

Same name and namespace in other branches
  1. 5.2 elysia_cron.admin.inc \elysia_cron_settings_form_validate()
  2. 5 elysia_cron.admin.inc \elysia_cron_settings_form_validate()
  3. 6.2 elysia_cron.admin.inc \elysia_cron_settings_form_validate()
  4. 6 elysia_cron.admin.inc \elysia_cron_settings_form_validate()
  5. 7 elysia_cron.admin.inc \elysia_cron_settings_form_validate()

Validate handler for 'elysia_cron_settings_form' form.

Parameters

array $form: Form API array.

array $form_state: Filled form_state array with input values.

File

./elysia_cron.admin.inc, line 650
Admin page callbacks for the elysia cron module.

Code

function elysia_cron_settings_form_validate(array $form, array &$form_state) {
  $values = $form_state['values'];
  $script = $form_state['values']['elysia_cron_script'];
  if ($script) {
    $errors = elysia_cron_decode_script($script, FALSE);
    if ($errors) {
      form_set_error('elysia_cron_script', t('Invalid lines:') . implode('<br>', $errors));
    }
  }
  foreach ($values as $key => $value) {
    if ($value && (preg_match('/^_elysia_cron_([^_]+_[^_]+)_(.*)$/', $key, $r) && ($r[1] == 'job_rule' || $r[1] == 'ch_rule') || $key == 'elysia_cron_default_rule')) {
      if (!preg_match('/^\\s*([0-9*,\\/-]+[ ]+[0-9*,\\/-]+[ ]+[0-9*,\\/-]+[ ]+[0-9*,\\/-]+[ ]+[0-9*,\\/-]+)\\s*$/', $value)) {
        form_set_error($key, t('Invalid rule: %rule', array(
          '%rule' => $value,
        )));
      }
    }
  }
  if (!empty($values['elysia_cron_default_rules'])) {
    $rules = explode(PHP_EOL, $values['elysia_cron_default_rules']);
    foreach ($rules as $rule) {
      $rule = trim($rule);
      if (empty($rule)) {
        continue;
      }
      $rule = explode('=', $rule);
      if (empty($rule[1])) {
        form_set_error('elysia_cron_default_rules', t('Invalid rule: %rule', array(
          '%rule' => $rule[0],
        )));
      }
      elseif (!preg_match('/^\\s*([0-9*,\\/-]+[ ]+[0-9*,\\/-]+[ ]+[0-9*,\\/-]+[ ]+[0-9*,\\/-]+[ ]+[0-9*,\\/-]+)\\s*$/', trim($rule[1]))) {
        form_set_error('elysia_cron_default_rules', t('Invalid rule: %rule', array(
          '%rule' => $rule[0],
        )));
      }
    }
  }
}