You are here

function dialog_get_form in Dialog 6

Generic dialog replacement for drupal_get_form(). Suitable for use as the page callback in a menu item.

This function introduces a new form callback function to handle the post-submit dialog commands, in the ajax context. This function takes the form of form_id_dialog_success. If this function is found, it will be automatically called after a valid submission of the form has been detected. If the function does not exist, a redirect will be issued based on the redirect value in the form_state array. As the final fallback, if the redirect value is missing or empty, a client-side reload command is issued.

Parameters

$id: The form_id that would normally be passed to drupal_get_form.

$js: The %ctools_js wildcard parameter to specify when the call is being made in a javascript context.

...: Any additional parameters will be passed on to the form builder function.

1 string reference to 'dialog_get_form'
dialog_user_menu in modules/dialog_user/dialog_user.module
Implementation of hook_menu().

File

./dialog.module, line 195

Code

function dialog_get_form($form_id, $js) {
  $args = func_get_args();
  $form_id = array_shift($args);
  $js = array_shift($args);
  $form_state = array(
    'ajax' => (bool) $js,
    'title' => drupal_get_title(),
    'args' => $args,
  );
  $output = dialog_form_wrapper($form_id, $form_state);
  if ($js) {
    ctools_include('ajax');
    if (empty($output)) {
      $func = $form_id . '_dialog_success';
      if (function_exists($func)) {
        $output = $func($form_state);
      }
      else {
        if (!empty($form_state['redirect'])) {
          $output[] = ctools_ajax_command_redirect($form_state['redirect']);
        }
        else {
          $output[] = ctools_ajax_command_reload();
        }
      }
    }
    ctools_ajax_render($output);
  }
  else {
    return $output;
  }
}