You are here

function _protected_node_admin_settings_validate in Protected Node 6

Same name and namespace in other branches
  1. 7 protected_node.settings.inc \_protected_node_admin_settings_validate()
  2. 1.0.x protected_node.settings.inc \_protected_node_admin_settings_validate()

Validate the submitted settings form from.

This function verifies that a global password is defined if the user defines that the global password should be used by default.

1 string reference to '_protected_node_admin_settings_validate'
protected_node_admin_settings in ./protected_node.settings.inc
Define the settings form

File

./protected_node.settings.inc, line 527
Configuration file for the protected_node module.

Code

function _protected_node_admin_settings_validate($form, &$form_state) {

  // make sure that a password is included if a global password is required
  // and none was ever submitted before
  switch ($form_state['values']['protected_node_use_global_password']) {
    case PROTECTED_NODE_PER_NODE_AND_GLOBAL_PASSWORD:
    case PROTECTED_NODE_GLOBAL_PASSWORD:
      if (!$form_state['values']['protected_node_global_password_field'] && !variable_get('protected_node_global_password', '')) {
        form_error($form['protected_node_security']['protected_node_global_password_field'], t('A global password is required to make use of the global password functionality.'));
      }
      break;
  }

  // if defined, the email box parameter must be a valid size
  $email_box = trim($form_state['values']['protected_node_email_box']);
  if ($email_box) {
    if (!preg_match('/[0-9]+x[0-9]+/', $email_box)) {
      form_error($form['protected_node_security']['protected_node_email_box'], t('The email box must be two numbers separated by the letter x in lowercase.'));
    }
    else {
      list($width, $height) = explode('x', $email_box);
      if ($width < 10 || $height < 2) {
        form_error($form['protected_node_security']['protected_node_email_box'], t('The email box must have a width of at least 10 and a height of at least 2.'));
      }
    }
  }
  if ($form_state['values']['protected_node_email_from']) {
    if (!valid_email_address($m)) {
      form_error($form['protected_node_auto_email']['protected_node_email_from'], t('The From email address is not valid.'));
    }
  }
}