You are here

function faq_ask_form in FAQ_Ask 6

Implementation of hook_form(). This is the "ask question" form.

2 string references to 'faq_ask_form'
faq_ask_edit in ./faq_ask.module
Get the edit question form.
faq_ask_page in ./faq_ask.module
Get the ask question form.

File

./faq_ask.module, line 173
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_form($form_state, $tid, $node) {
  $form = array();

  // We will allow term suggestions only if the setting is chosen
  //  AND there is a vocabulary named "FAQ."
  $vid = db_result(db_query_range("SELECT vid FROM {vocabulary} WHERE name='FAQ'", 0, 1));
  $suggest = variable_get('faq_ask_suggest', FALSE) && $vid;

  // Find all the categories for which we have experts.
  $result = db_query(db_rewrite_sql('SELECT DISTINCT(t.name), e.tid FROM {term_data} t JOIN {faq_expert} e USING (tid)', 't', 'tid'));
  $cat_list = array();
  while ($row = db_fetch_object($result)) {
    $cat_list[$row->tid] = $row->name;
  }
  if (count($cat_list) == 0) {
    $msg = t('Currently, there are no categories defined. ') . ' ';
    if (user_access('administer faq')) {
      $msg .= t('Please go to the <a href="!url">settings page</a> to configure this module.', array(
        '!url' => url('admin/settings/faq/ask'),
      ));
    }
    else {
      $msg .= t('Please <a href="!url">ask your site administrator</a> to set up this feature.', array(
        '!url' => url('user/1/contact'),
      ));
    }
    drupal_set_message($msg, 'error');
    return;
  }
  if ($suggest) {
    $cat_list[0] = t('-suggest a category-');
    $form['#redirect'] = FALSE;
    $form['faq_vid'] = array(
      '#type' => 'value',
      '#value' => $vid,
    );
    if (!$tid) {
      $default_tid = 0;
    }
  }

  // If a nid exists, then get the existing values.
  if ($node) {
    $nid = $node->nid;
    $title = $node->title;
    $taxo = array_keys($node->taxonomy);
    $default_tid = $taxo[0];
    $detailed_question = $node->detailed_question;
  }
  else {
    $nid = NULL;
    $default_tid = $tid;
    $title = NULL;
    $detailed_question = NULL;
  }
  $form['nid'] = array(
    '#type' => 'value',
    '#value' => $nid,
  );

  // Category.
  $expert_categorize = variable_get('faq_ask_categorize', FALSE);

  // Check if only experts can categorize the question.
  if (!$expert_categorize) {
    $form['category'] = array(
      '#title' => t('Category'),
      '#type' => 'select',
      '#options' => $cat_list,
      '#default_value' => $default_tid,
      '#required' => TRUE,
      '#weight' => -3,
      '#description' => t('Please select the correct category for your question.'),
    );
  }
  else {
    $form['category'] = array(
      '#type' => 'value',
      '#value' => -1,
    );
  }
  if (count($form_state['post']) > 0) {
    if ($form_state['post']['category'] == 0) {
      $form['new_cat'] = array(
        '#title' => t('Suggested Category'),
        '#type' => 'textfield',
        '#weight' => -1,
        '#default_value' => NULL,
        '#description' => t('Please enter your suggested category for the question.'),
      );
    }
  }

  // Question.
  $question_length = variable_get('faq_question_length', 'short');
  $cols = variable_get('faq_ask_title_len', 60);

  // Long questions enabled.
  $form['title'] = array(
    '#type' => 'textarea',
    '#cols' => $cols,
    '#title' => t('Question summary'),
    '#required' => TRUE,
    '#default_value' => $title,
    '#weight' => -1,
    '#description' => t('Enter your question here. It will be answered as soon as possible.'),
  );
  $form['detailed_question'] = array(
    '#type' => 'textarea',
    '#title' => t('Details'),
    '#required' => TRUE,
    '#default_value' => $detailed_question,
    '#weight' => 0,
    '#cols' => $cols,
    '#rows' => 5,
    '#description' => t('Enter your question here. It will be answered as soon as possible.'),
  );
  $form['send'] = array(
    '#type' => 'submit',
    '#value' => t('Send my question'),
    '#weight' => 3,
  );
  return $form;
}