function uc_roles_user_validate in Ubercart 7.3
Same name and namespace in other branches
- 6.2 uc_roles/uc_roles.module \uc_roles_user_validate()
User profile form validate handler.
See also
uc_roles_form_user_profile_form_alter()
1 string reference to 'uc_roles_user_validate'
- uc_roles_form_user_profile_form_alter in uc_roles/
uc_roles.module - Implements hook_form_user_profile_form_alter().
File
- uc_roles/
uc_roles.module, line 250 - Grants roles upon accepted payment of products.
Code
function uc_roles_user_validate($form, &$form_state) {
$edit = $form_state['values'];
$account = $form_state['build_info']['args'][0];
if (isset($form_state['build_info']['args'][1])) {
$category = $form_state['build_info']['args'][1];
}
else {
// user_profile_form() has a default value for $category.
$category = 'account';
}
// Validate the amount of time for the expiration.
if (!empty($edit['new_role']) && $category == 'account') {
if (intval($edit['new_role_add_qty']) < 1) {
form_set_error('new_role_add_qty', t('The expiration length must be a positive integer'));
}
}
// Validate adjusted expirations.
if (isset($edit['table'])) {
foreach ((array) $edit['table'] as $rid => $value) {
// We don't validate if nothing was actually selected, the role, or the
// expiration is removed.
if ($value['qty'] == 0 || $value['remove'] == 1 || !$edit['roles'][$rid]) {
continue;
}
$qty = $value['qty'];
$qty *= $value['polarity'] == 'add' ? 1 : -1;
$new_expiration = _uc_roles_get_expiration($qty, $value['granularity'], $value['expiration']);
if (REQUEST_TIME > $new_expiration) {
form_set_error('qty', t("The new expiration date, %date, has already occurred.", array(
'%date' => format_date($new_expiration, 'short'),
)));
}
}
}
}