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(&$form, &$form_state, $form_id) {
    if ($form_id == 'comment_form') {
      echo 'test';

function _mycaptcha_get_ask($key = NULL) {

  $ask = array(
    'test 1' => 'example 1',
    'test 2' => 'example 2',

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

function mycaptcha_ask_form(&$form) {
  $ask = _mycaptcha_get_ask();
  if (isset($_SESSION['mycaptcha_ask_key']) && $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' => 'textfield',
    '#required' => 1,
    '#title' => 'tetst'.$ask_key,
    '#weight' => -1

1 Answer 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
  • you're right. my $form_id is wrong. how do you know the $form_id? thank you. but why when i used "comment_form" in template.php. it can alter the comment field title. thank you. Jun 29, 2011 at 8:16
  • 1
    You can drupal_set_message($form_id) in your hook_form_alter() (or just print, var_dump, whatever) and just go to the page the form is displayed on, then you will see your id (you could see more than one if there are more forms on the page, but it's usually pretty easy to know which id is for which form). Jun 29, 2011 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.