You are here

function regcode_roles_admin_validate in Registration codes 6

Same name and namespace in other branches
  1. 6.2 regcode_roles/regcode_roles.module \regcode_roles_admin_validate()
  2. 7.2 regcode_roles/regcode_roles.module \regcode_roles_admin_validate()
  3. 7 regcode_roles/regcode_roles.module \regcode_roles_admin_validate()

Validate date input

File

regcode_roles/regcode_roles.module, line 159

Code

function regcode_roles_admin_validate($form, $form_state) {

  // Role expire stuff
  if (module_exists('role_expire')) {
    if (!empty($form_state['values']['expiry_duration'])) {
      if ((int) $form_state['values']['expiry_duration'] < 1) {
        form_set_error('expiry_duration', t('Invalid duration provided, duration must be greater than or equal to 1 day.'));
      }
    }
    if (!empty($form_state['values']['expiry_date'])) {
      if (!($expire_date = strtotime($form_state['values']['expiry_date']))) {
        form_set_error('expiry_date', t('Invalid date provided, please provide a date in a format strtotime can handle.'));
      }
      elseif ($expire_date < time()) {
        form_set_error('expiry_date', t('Expiry date must be in the future.'));
      }
    }
  }
}