You are here

function _ajax_register_execute_form in Ajax Login/Register 7.4

Executes form.

4 calls to _ajax_register_execute_form()
ajax_register_page_callback in ./ajax_register.pages.inc
Returns USER LOGIN / REGITER / PASSWORD form.
ajax_register_user_login_ajax_callback in ./ajax_register.module
Ajax callback for USER LOGIN form.
ajax_register_user_pass_ajax_callback in ./ajax_register.module
Ajax callback for USER PASS form.
ajax_register_user_register_form_ajax_callback in ./ajax_register.module
Ajax callback for USER REGISTER form.

File

./ajax_register.module, line 298

Code

function _ajax_register_execute_form($form_type, $form_state) {

  // Include additinal ajax commands.
  ctools_include('ajax');
  ctools_include('modal');
  $redirect_behavior = variable_get('ajax_register_' . $form_type . '_redirect_behavior', 'default');
  $redirect_url = variable_get('ajax_register_' . $form_type . '_redirect_url', '');

  // Use the form state's redirect url for default behavior.
  if ($redirect_behavior == 'default' && !empty($form_state['redirect'])) {
    if (is_array($form_state['redirect'])) {
      $redirect_url = call_user_func_array('url', $form_state['redirect']);

      // Remove leading slash from the url.
      $redirect_url = drupal_substr($redirect_url, 1);
    }
    else {
      $redirect_url = $form_state['redirect'];
    }
  }
  elseif ($redirect_behavior == 'custom' && !empty($redirect_url) || $redirect_behavior == 'none') {

    // Do nothing other than preventing the fallback.
  }
  else {
    $redirect_behavior = 'refresh';
  }

  // Provide additional logic and titles for different form types.
  switch ($form_type) {
    case 'password':
      $title = t('Successful password request');
      break;
    case 'register':
      $title = t('Successful registration');
      break;
    case 'login':
      $title = t('Successful login');
      $message = 'Login was successful. ';
      if ($redirect_behavior == 'refresh') {
        $message .= 'Page will now be reloaded.';
      }
      elseif ($redirect_behavior == 'default' || $redirect_behavior == 'custom') {
        $message .= 'Page will now be redirected.';
      }
      drupal_set_message(check_plain(t($message)));
      $commands[] = ctools_modal_command_display($title, theme('status_messages'));
      break;
  }

  // Send ajax command to modal based on redirect behavior.
  switch ($redirect_behavior) {
    case 'none':
      $commands[] = ctools_modal_command_display($title, theme('status_messages'));
      break;
    case 'refresh':
      $commands[] = ctools_ajax_command_reload();
      break;
    default:

      // Redirect to URL supplied from default or custom redirect behavior.
      $commands[] = ctools_ajax_command_redirect($redirect_url);
      break;
  }
  return $commands;
}