You are here

function role_expire_user_admin_role_validate in Role Expire 7

Same name and namespace in other branches
  1. 8 role_expire.module \role_expire_user_admin_role_validate()
  2. 6 role_expire.module \role_expire_user_admin_role_validate()
  3. 2.x role_expire.module \role_expire_user_admin_role_validate()

Form validation handler invoked by role_expire_form_user_admin_role_alter. Ensure that the specified duration is a valid, relative, positive strtotime- compatible string.

_state

Parameters

$form:

1 string reference to 'role_expire_user_admin_role_validate'
role_expire_form_user_admin_role_alter in ./role_expire.module
Implements hook_form_FORM-ID_alter().

File

./role_expire.module, line 347
Role Expire module

Code

function role_expire_user_admin_role_validate($form, &$form_state) {
  if (!empty($form_state['values']['role_expire'])) {

    // Capture the duration from the form
    $duration_string = check_plain($form_state['values']['role_expire']);

    // Make sure it's a *relative* duration string. That is, it will result in a
    // different strtotime when a different 'now' value is used.
    $now = time();
    $timestamp = strtotime($duration_string, $now);
    $timestamp2 = strtotime($duration_string, $now - 100);
    if ($timestamp === FALSE || $timestamp < 0) {
      form_set_error('role_expire', t('Role expiry default duration must be a strtotime-compatible string.'));
    }
    elseif ($timestamp < $now) {
      form_set_error('role_expire', t('Role expiry default duration must be a <strong>future</strong> strtotime-compatible string.'));
    }
    elseif ($timestamp == $timestamp2) {

      // This is an absolute (or special) timestamp. That's not allowed.
      form_set_error('role_expire', t('Role expiry default duration must be a <strong>relative</strong> strtotime-compatible string.'));
    }

    // not relative
  }

  // !empty
}