douwu3763 2014-04-03 08:32
浏览 94
已采纳

Drupal - 找不到自定义模块的页面

I'm fairly new to Drupal and just made my first module wich shows a form. In the hook_menu(), I set $items['form'], as you can see below. While I navigate to mysite.com/form, it doesn't show me anything, except for the theme and: Page not found, The requested page "/form" could not be found.

I tried to clear my cache, to give my module a different name, made sure my module is enabled, nothing helps. Does anyone knows what the problem might be? The code from the .module file is right here:

<?php 

//implements hook_permission()
function form_example_permission() {
  return array(
    'Submit form_example' => array(
      'title' => t('Submit form_example'),
      'description' => t('Submit the form_example form'),
    ),
  );
}


//implements hook_menu()
function form_example_menu() {
  $items['form'] = array(
    'title' => 'My Example Form',
    'type' => MENU_NORMAL_ITEM,
    'acces' => TRUE,
    'page callback' => 'drupal_get_form()',
    'page arguments' => array('form_example_form'),
    'acces arguments' => array('acces content'),
  );

  return $items;
}

//implements hook_form()
function form_example_form($form, &$form_state) {
  $form['mynumber'] = array (
    '#type' => 'textfield',
    '#title' => t('My Number'),
    '#size' => 10,
    '#maxlength' => 10,
    '#required' => TRUE,
    '#description' => t('Please enter a valid number'),
  );

  $form['mytextfield'] = array(
    '#type' => 'textfield',
    '#title' => t('My Textfield'),
    '#size' => 60,
    '#maxlength' => 128,
    '#required' => TRUE,
  );

  $form['mytext'] = array(
    '#title' => t('My Textarea'),
    '#type' => 'textarea',
    '#description' => t('Enter some text'),
    '#default value' => '',
    '#required' => TRUE,
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add item'),
  );

  return $form;
}
  • 写回答

2条回答 默认 最新

  • duandeng2265 2014-04-03 10:59
    关注

    'page callback' => 'drupal_get_form() is wrong, you need to remove brackets from function name. The right implementation will be page callback' => 'drupal_get_form. And also acces => TRUE is wrong, it must be 'access callback', and if you set fixed TRUE value then you don't need to specify access arguments key. Because access callback return TRUE anyway. For further reading..

    UPDATE: Example:

    function form_example_permission() {
      return array(
        'submit form_example' => array(
          'title' => t('Submit form_example'),
          'description' => t('Submit the form_example form'),
        ),
      );
    }
    
    
    //implements hook_menu()
    function form_example_menu() {
      $items['form'] = array(
        'title' => 'My Example Form',
        'type' => MENU_NORMAL_ITEM,
        'access callback' => 'user_access',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('form_example_form'),
        'access arguments' => array('submit form_example'),
      );
    
      return $items;
    }
    

    (you had a typo in you code) Don't forget to flush the cache.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵