You are here

function agreement_form_submit in Agreement 6

Same name and namespace in other branches
  1. 6.2 agreement.module \agreement_form_submit()
  2. 7.2 agreement.pages.inc \agreement_form_submit()

Submit handler for agreement_form()

See also

agreement_form()

agreement_form_validate()

File

./agreement.module, line 404
agreement.module - Agreement module code

Code

function agreement_form_submit($form, &$form_state) {
  $uid = $form_state['values']['uid'];
  $agree = $form_state['values']['agree'];

  //TODO: Don't always delete existing agreements
  db_query("DELETE FROM {agreement} WHERE uid='%d'", $uid);
  db_query("INSERT INTO {agreement} (uid, agreed, sid, agreed_date)\n    VALUES (%d, %d, '%s', %d)", $uid, $agree, session_id(), time());
  drupal_set_message(check_plain(variable_get('agreement_message_success', AGREEMENT_MESSAGE_SUCCESS)));
  $agreement_success_destination = check_plain(variable_get('agreement_success_destination', ''));
  $agreement_success_destination = str_replace('&lt;front&gt;', '<front>', $agreement_success_destination);
  if ($_SESSION['agreement_destination'] == 'change password') {

    // Always go to user/%/edit page if original destination was user/reset.
    $redirect = 'user/' . $uid . '/edit';
  }
  elseif ($agreement_success_destination == '') {
    if ($_SESSION['agreement_destination'] == '') {
      $redirect = '<front>';
    }
    else {
      $redirect = $_SESSION['agreement_destination'];
    }
  }
  else {
    $redirect = $agreement_success_destination;
  }
  $form_state['redirect'] = $redirect;
  return;
}