function user_badges_change_form_submit in User Badges 7.2
Same name and namespace in other branches
- 6.2 user_badges.module \user_badges_change_form_submit()
- 6 user_badges.module \user_badges_change_form_submit()
- 7.4 user_badges.module \user_badges_change_form_submit()
- 7 user_badges.module \user_badges_change_form_submit()
- 7.3 user_badges.module \user_badges_change_form_submit()
Process user_badges_change_form form submissions.
Add the named badge. Remove the checked badges.
File
- ./
user_badges.module, line 708 - @brief User Badges module file
Code
function user_badges_change_form_submit($form, &$form_state) {
$uid = $form_state['values']['uid'];
//Add badges for non-empty fields
for ($i = 1; $i <= 5; $i++) {
if (!empty($form_state['values']['add' . $i])) {
$validation = user_badges_badge_autocomplete_validation($form_state['values']['add' . $i]);
user_badges_user_add_badge($uid, $validation[0], 'user');
}
}
//Remove any checked badges
$badges_to_go = array();
foreach ($form_state['values'] as $bid => $value) {
if (is_numeric($bid) && $value == 1) {
$badges_to_go[] = $bid;
}
}
if (count($badges_to_go)) {
foreach ($badges_to_go as $bid) {
user_badges_user_remove_badge($uid, $bid);
}
drupal_set_message(format_plural(count($badges_to_go), '1 badge removed.', '@count badges removed.'));
}
if (arg(2) == 'edit') {
$form_state['redirect'] = "user/{$uid}";
// My account.
}
else {
$form_state['redirect'] = "user/{$uid}/badges";
// Full admin UI.
}
}