You are here

function faq_ask_a_question_blockform in FAQ_Ask 6.2

Same name and namespace in other branches
  1. 7 faq_ask.module \faq_ask_a_question_blockform()

Block "Ask a Question" form implementation This implements the form displayed in a block where the user may ask a question

1 call to faq_ask_a_question_blockform()
faq_ask_block in ./faq_ask.module
Implementation of hook_block().

File

./faq_ask.module, line 662
This module is an add-on to the FAQ module that allows users with the 'ask question' permission to create a question which will be queued for an 'expert' to answer.

Code

function faq_ask_a_question_blockform() {

  // Include page handler for node_add()
  module_load_include('inc', 'node', 'node.pages');

  // If user is allowed to create a faq content type
  if (node_access('create', 'faq')) {

    // Fool the hook_form_alter function to think we're in an faq-ask page
    $saved_get = '';
    if (isset($_GET['ask'])) {
      $saved_get = $_GET['ask'];
    }
    $_GET['ask'] = '1';
    $_GET['block'] = 'TRUE';

    // Note title before rendering of form.
    $title = drupal_get_title();

    // Create the form
    $form = node_add('faq');

    // Restore title, which will have been overridden.
    drupal_set_title(check_plain($title));

    // Restore the $_GET['ask'] variable status
    if ($saved_get != '') {
      $_GET['ask'] = $saved_get;
    }
    else {
      unset($_GET['ask']);
    }
    unset($_GET['block']);
    return $form;
  }
  else {
    return '';
  }
}