php - Drupal:如何在与表单相同的页面上呈现表单结果

标签 php forms drupal drupal-6 drupal-fapi

如何在与表单本身相同的页面上打印表单提交的结果?

相关hook_menu:

    $items['admin/content/ncbi_subsites/paths'] = array(
        'title' => 'Paths',
        'description' => 'Paths for a particular subsite',
        'page callback' => 'ncbi_subsites_show_path_page',
        'access arguments' => array( 'administer site configuration' ),
        'type' => MENU_LOCAL_TASK,
    );

页面回调:

function ncbi_subsites_show_path_page() {
  $f = drupal_get_form('_ncbi_subsites_show_paths_form');
  return $f;
}

表单构建函数:

   function _ncbi_subsites_show_paths_form() {
      // bunch of code here

      $form['subsite'] = array(
        '#title' => t('Subsites'),
        '#type' => 'select',
        '#description' => 'Choose a subsite to get its paths',
        '#default_value' => 'Choose a subsite',
        '#options'=> $tmp,
      );

      $form['showthem'] = array(
        '#type' => 'submit',
        '#value' => 'Show paths',
        '#submit' => array( 'ncbi_subsites_show_paths_submit'),    
      );

      return $form;
    }

提交功能(为简洁起见跳过验证功能)

function ncbi_subsites_show_paths_submit( &$form, &$form_state ) {
  //dpm ( $form_state );
  $subsite_name = $form_state['values']['subsite'];
  $subsite = new Subsite( $subsite_name ); //y own class that I use internally in this module
  $paths = $subsite->normalized_paths;

  // build list
  $list = theme_item_list( $paths );
}

如果我打印那个 $list 变量,它正是我想要的,但我不确定如何将它放入包含从“ncbi_subsites_show_path_page”构建的原始表单页面的页面。非常感谢任何帮助!

最佳答案

Nikit 发布的链接中的关键信息是 $form_state['rebuild']。这是来自 Drupal 7 文档的一些信息,我相信这些信息同样适用于 Drupal 6...

$form_state['rebuild']: Normally, after the entire form processing is completed and submit handlers ran, a form is considered to be done and drupal_redirect_form() will redirect the user to a new page using a GET request (so a browser refresh does not re-submit the form). However, if 'rebuild' has been set to TRUE, then a new copy of the form is immediately built and sent to the browser; instead of a redirect. This is used for multi-step forms, such as wizards and confirmation forms. Also, if a form validation handler has set 'rebuild' to TRUE and a validation error occurred, then the form is rebuilt prior to being returned, enabling form elements to be altered, as appropriate to the particular validation error.

关于php - Drupal:如何在与表单相同的页面上呈现表单结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2733306/

相关文章:

php - 当我尝试执行 symfony 命令时,未定义命令 "set-info"

php - 如何更新 PHP CLI OSX?

javascript - 禁止在 html 中查看过去的内容/历史记录

javascript - 谷歌中的适当事件用鼠标放置自动完成选择

html - 将 html 主题转换为 drupal 主题后响应不起作用

php - 保护 PHP 源代码

php - 将 Javascript 点击计数传递给 php

jquery - 带有添加新字段的按钮的表单

android - Drupal 通过从 android 调用 push_notification 服务删除 token

php - drupal View 对这个用例有用吗