You are here

function answers_form_alter in Answers 7.4

Same name and namespace in other branches
  1. 5.2 answers.module \answers_form_alter()
  2. 6 answers.module \answers_form_alter()
  3. 7 answers.module \answers_form_alter()
  4. 7.2 answers.module \answers_form_alter()

Implements hook_form_alter().

File

./answers.module, line 299
The Answers module.

Code

function answers_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'answers_answer_node_form') {

    // Disallow adding an answer that is not attached to a question.
    $node = $form['#node'];
    if (!isset($node->answers_related_question[LANGUAGE_NONE][0]['target_id'])) {
      drupal_set_message(t('You cannot post an !answer without a !question.', answers_translation()), 'error');
      drupal_not_found();
      exit;
    }

    // Disallow manually assigning an answer to a question.
    hide($form['answers_related_question']);
    $form['body'][LANGUAGE_NONE][0]['#title'] = '';
  }
  elseif ($form_id == 'answers_question_node_form') {

    // Disallow manually setting the question lock.
    hide($form['question_locks']);
  }
}