function user_badges_change_form_submit in User Badges 7.3
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.2 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 762 - @brief User Badges module file
Code
function user_badges_change_form_submit($form, &$form_state) {
$uid = $form_state['values']['uid'];
//If the user used the multi drop-down to select badges, submit them accordingly
if (variable_get('user_badges_selector_type', 1) == 0) {
foreach ($form_state['values']['add_drop_down'] as $bid) {
//We have to add this validation as we don't want to add the - None - case which might have been selected
if ($bid > 0) {
user_badges_user_add_badge($uid, $bid, 'user');
}
}
}
else {
//Add badges for non-empty fields
for ($i = 1; $i <= 5; $i++) {
if (!empty($form_state['values']['add_autocomplete' . $i])) {
$validation = user_badges_badge_autocomplete_validation($form_state['values']['add_autocomplete' . $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.
}
}