You are here

function colorbox_node_form_ajax_support in Colorbox Node 7.3

_state _id

Parameters

$form:

string $action: The action to take when the form is completed. close = Closes the colorbox modal. redirect = Closes the colorbox modal and redirects the user to the $destination url reload = Reloads the current page. This is good for the login form. replace = Replaces the form/ajax data with the provided $destination.

string $destination:

5 calls to colorbox_node_form_ajax_support()
colorbox_node_form_node_form_alter in ./colorbox_node.module
Adds AJAX support to the node edit form inside a colorbox modal.
colorbox_node_form_user_login_alter in ./colorbox_node.module
Adds AJAX support to the login form inside a colorbox modal.
colorbox_node_form_user_pass_alter in ./colorbox_node.module
Adds AJAX support to the user pass reset form inside a colorbox modal.
colorbox_node_form_user_profile_form_alter in ./colorbox_node.module
Adds AJAX support to the user edit form inside a colorbox modal.
colorbox_node_form_user_register_form_alter in ./colorbox_node.module
Adds AJAX support to the registration form inside a colorbox modal.

File

./colorbox_node.module, line 143
Creates a menu callback with support for displaying a node inside of a colorbox.

Code

function colorbox_node_form_ajax_support(&$form, &$form_state, $form_id, $action = 'close', $destination = '') {

  // Check to see if we are inside an active colorbox
  if (colorbox_node_is_active() || isset($form_state['#colorboxNode'])) {

    // Set our form to be active as AJAX upload fields will be in a
    // different context and this code will never be called again and will fail out.
    $form_state['#colorboxNode'] = TRUE;
    $form['#prefix'] = '<div id="colorboxNode-' . $form_id . '-Wrapper">';
    $form['#suffix'] = '</div>';
    $form['actions']['submit']['#id'] = 'colorboxNode-' . $form_id . '-Submit';
    $form['actions']['submit']['#ajax'] = array(
      'callback' => 'colorbox_node_ajax_submit',
      'wrapper' => 'colorboxNode-' . $form_id . '-Wrapper',
      'method' => 'replace',
      'effect' => 'fade',
    );
    if ($action == 'reload') {
      $form['#cbox_reload'] = TRUE;
    }
    elseif ($action == 'redirect') {
      $form['#cbox_redirect'] = $destination;
    }
    elseif ($action == 'replace') {
      $form['#cbox_replace'] = $destination;
    }
  }
}