function agreement_form_submit in Agreement 7.2
Same name and namespace in other branches
- 6.2 agreement.module \agreement_form_submit()
- 6 agreement.module \agreement_form_submit()
Submit handler for agreement_form().
See also
File
- ./
agreement.pages.inc, line 117 - Agreement page callbacks.
Code
function agreement_form_submit($form, &$form_state) {
$account = $form_state['account'];
$info = $form_state['info'];
$uid = $account->uid;
$agree = $form_state['values']['agree'];
$had_agreed = $form_state['agreed'];
try {
$transaction = db_transaction();
$mail_key = $agree ? 'notice' : 'revoked';
$message = $agree ? $info['settings']['success'] : $info['settings']['revoked'];
agreement_agree($account, $info['name'], $agree);
drupal_set_message(check_plain($message));
// Send email notifying of acceptance if admin has set an email address.
if ($info['settings']['email_recipient'] && (!$had_agreed || !$agree)) {
$params['account'] = $account;
drupal_mail('agreement', $mail_key, $info['settings']['email_recipient'], user_preferred_language($account), $params);
}
$agreement_success_destination = str_replace('<front>', '<front>', check_plain($info['settings']['destination']));
if (isset($_SESSION['agreement_destination']) && $_SESSION['agreement_destination'] === 'change password') {
// Always go to the user account edit page if original destinatino was
// user/reset.
$redirect = 'user/' . $uid . '/edit';
}
elseif (!$agreement_success_destination) {
$redirect = isset($_SESSION['agreement_destination']) ? $_SESSION['agreement_destination'] : '<front>';
}
else {
$redirect = $agreement_success_destination;
}
unset($_SESSION['agreement_destination']);
$form_state['redirect'] = $redirect;
} catch (\PDOException $e) {
$transaction
->rollback();
drupal_set_message(t('An error occurred accepting the agreement.'), 'error');
}
}