dousong5161 2011-05-13 20:38
浏览 38
已采纳

Drupal 7中的多个表单

I wish to add a "todo" list to my site so that a logged in user can maintain a simple list of tasks to do. Conceptually I want to display an array of input boxes, allowing the user to edit any of the existing tasks, add a new task, or delete an existing task. Each input box will be its own form so that changes can be submitted one-by-one. I'm completely new to drupal and can't seem to find any resource online that can show how to achieve this.

  • 写回答

2条回答 默认 最新

  • dpzr52746 2011-05-13 20:43
    关注

    You need to write a page callback which calls drupal_get_form several times. If the same form builder handles the forms, then you need to implement hook_forms.

    function foo_menu() {
      $items['foo'] = array(
        'page callback' => 'foo_page',
        'access arguments' => array('access foo'),
      );
      return $items;
    }
    function foo_page() {
      for ($i = 0; $i < 10; $i++) {
        $build[] = drupal_get_form('foo_form_' . $i, $i);
      }
      return $build;
    }
    function foo_forms($form_id, $args) {
      if (!empty($args) && $form_id == 'foo_form_' . $args[0]) {
        $forms[$form_id]['callback'] = 'foo_form';
      }
      return $forms;
    }
    function foo_form($form, $form_state, $i) {
      return $form;
    }
    

    Of course, if the forms are different then omit foo_forms and just write foo_form_0, foo_form_1 etc etc.

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路