1

I'm trying to create a custom module that has a block with a form in it. I'm able to install my module, and even add the block to the content area of the site, showing my form on every page of the site. But for some reason the page I set as the form's page won't show up in the navigation, and when I try to type in the pages address to get to it, it says the page is not found.

<?php
require_once('/includes/functions.php');
/**
 * @file
 *
 */

 /**
 * Implements hook_block_menu()
  */

 function search_engine_menu() {
    $items = array();
    $items['results_page'] = array(
        'title'         => 'Search Results',
        'page callback'     => 'search_engine_results_page',
        'access callback'   => TRUE,
        'type'          => MENU_NORMAL_ITEM,
    );

 }


 /**
 * Implements hook_block_info().
 */

 function search_engine_block_info() {
     $blocks = array();
     $blocks['search_engine'] = array(
        'info' => t('Search Engine'),
        'cache'=> DRUPAL_CACHE_GLOBAL,
        );

    return $blocks;
 }

 /**
 * Implements hook_block_view().
 */

 function search_engine_block_view($delta = ''){
     $block = array();
     switch ($delta) {
     case 'search_engine':
         $block['subject'] = t('Search Engine');
         $block['content'] = drupal_get_form('search_engine_form'); 
     }  

     return $block;
 }


 /**
 * Implements hook_form.
 */

 function search_engine_form ($form, &$form_state){
        $form['searchOptions'] = array(
            '#type'     => 'select',
            '#title'    => t('You can search by GWF Number, name, email address or phone number.'),
            '#options'  => array(
                'gwf'           => t('GWF Number'),
                'applicant_email'   => t('Email Address'),
                'name'          => t('Name'),
                'phone_number'      => t('Phone Number'),
                ),
            '#value'    => 'gwf',
            );
        $form['searchInput'] = array(
            '#type'     => 'textfield',
            '#title'    => t(''),
            );
        $form['submit'] = array(
            '#type' => 'submit',
            '#value'=> t('Submit'),
            );
        $form['results'] = array(
            '#type' => 'markup',
            '#value'=> 'Test',
        );


    return $form;       
 }
 /**
 * Implements hook_form_submit.
 */

 function search_engine_form_submit($form, &$form_state){
    drupal_set_message('Submitted');
 }

2 Answers 2

2

At the end of your search_engine_menu() function, you need to return $items. Also, you should clear your drupal cache after adding a new menu item.

 function search_engine_menu() {
    $items = array();
    $items['results_page'] = array(
        'title'         => 'Search Results',
        'page callback'     => 'search_engine_results_page',
        'access callback'   => TRUE,
        'type'          => MENU_NORMAL_ITEM,
    );
    return $items;
 }
2
  • DUH! Thanks so much, it's the simplest things sometimes :-)
    – slpcc63
    Feb 13, 2014 at 17:49
  • No problemo :) Glad it worked!
    – Mike2012
    Feb 13, 2014 at 17:56
1

The hook_menu should return the $items array. Don't forget to clear the cache after.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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