You are here

function disable_messages_settings_form_validate in Disable Messages 7

Same name and namespace in other branches
  1. 6 disable_messages.module \disable_messages_settings_form_validate()

Validation function for disable_messages_settings_form.

File

./disable_messages.module, line 418
The disable_messages module file.

Code

function disable_messages_settings_form_validate($form, &$form_state) {
  global $_disable_messages_error, $_disable_messages_error_no;
  $patterns = explode("\n", $form_state['values']['disable_messages_ignore_patterns']);

  // Override drupal error handler to handle the preg error here.
  set_error_handler('_disable_messages_error_handler');
  foreach ($patterns as $pattern) {
    $pattern = preg_replace(array(
      '/^\\s*/',
      '/\\s*$/',
    ), '', $pattern);
    try {
      preg_match('/' . $pattern . '/su', "This is a test string");
    } catch (Exception $e) {
    }
    if ($_disable_messages_error) {
      form_set_error('disable_messages_ignore_patterns', t('"@pattern" is not a valid regular expression. Preg error (@error_no) - @error', array(
        '@pattern' => $pattern,
        '@error_no' => $_disable_messages_error_no,
        '@error' => $_disable_messages_error,
      )));
      restore_error_handler();
      return;
    }
  }
}