Why isn't the code in my implementation of hook_form_alter() being called? When I test to see if my form is called by checking for its $form_id, there is no output. Why is it that under the comment form it can't invoke the mymodule_ask_form?

/**
 * @Implement of hook_form_alter()
 */
function mycaptcha_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    if ($form_id == 'comment_form') {
      mycaptcha_ask_form($form);
      echo 'test';
    }
  }   

function _mycaptcha_get_ask($key = NULL) {

  $ask = array(
    'test 1' =&gt; 'example 1',
    'test 2' =&gt; 'example 2',
  );

  return isset($key) ? $ask[$key] : $ask;
}

function mycaptcha_ask_form(&amp;$form) {
  $ask = _mycaptcha_get_ask();
  if (isset($_SESSION['mycaptcha_ask_key']) &amp;&amp; $ask[$_SESSION['mycaptcha_ask_key']]) {
    $ask_key = $_SESSION['mycaptcha_ask_key'];
  }

  if (!$ask_key) {
    $_SESSION['mycaptcha_ask_key'] = $ask_key = array_rand($ask);
  }

  $form['mycaptcha_ask'] = array(
    '#type' =&gt; 'textfield',
    '#required' =&gt; 1,
    '#title' =&gt; 'tetst'.$ask_key,
    '#weight' =&gt; -1
  );
}
First of all - have you checked that Drupal sees your function at all, and calls it?

Then, have you tried printing out $form_id? As for default D7's content types (article and basic page) comment form ids are not "comment_form", but:


comment_node_article_form - for article
comment_node_page_form - for basic page