You are here

function terms_of_use_js in Terms of Use 6

Same name and namespace in other branches
  1. 7 terms_of_use.admin.inc \terms_of_use_js()

Menu callback for AHAH addition.

1 string reference to 'terms_of_use_js'
terms_of_use_menu in ./terms_of_use.module
Implementation of hook_menu().

File

./terms_of_use.pages.inc, line 27
Page callbacks for the Terms of Use module.

Code

function terms_of_use_js() {

  // Build the new form.
  $form_state = array(
    'submitted' => FALSE,
  );
  $form_build_id = $_POST['form_build_id'];

  // We retreive the cached form, add the element value, and resave.
  $form = form_get_cache($form_build_id, $form_state);
  if (isset($form['terms_of_use_text']['terms_of_use_node_title'])) {

    // Create the extra field
    $form['terms_of_use_text']['terms_of_use_node_id'] = array(
      '#type' => 'textfield',
      '#title' => t('Node id where your Terms of Use are published'),
      '#default_value' => variable_get('terms_of_use_node_id', ''),
      '#description' => t('Node <em>id</em> of the page or story (or blog entry or book page) where your Terms of Use are published.'),
    );
    unset($form['terms_of_use_text']['terms_of_use_node_title']);
    $form['terms_of_use_text']['terms_of_use_pick_node_id']['#value'] = t('I prefer to provide the title of the post');
  }
  else {

    // Create the extra field
    $form['terms_of_use_text']['terms_of_use_node_title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title of the post where your Terms of Use are published'),
      '#default_value' => variable_get('terms_of_use_node_title', ''),
      '#description' => t('Node <em>title</em> of the page or story (or blog entry or book page) where your Terms of Use are published.'),
      '#autocomplete_path' => 'node/autocomplete',
    );
    unset($form['terms_of_use_text']['terms_of_use_node_id']);
    $form['terms_of_use_text']['terms_of_use_pick_node_id']['#value'] = t('I prefer to specify the node id');
  }
  form_set_cache($form_build_id, $form, $form_state);
  $form += array(
    '#post' => $_POST,
    '#programmed' => FALSE,
  );

  // Rebuild the form.
  $form = form_builder('terms_of_use_admin_settings', $form, $form_state);

  // Render the new output.
  $output = drupal_render($form['terms_of_use_text']);
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));
}