• <i id='dCNEI'><tr id='dCNEI'><dt id='dCNEI'><q id='dCNEI'><span id='dCNEI'><b id='dCNEI'><form id='dCNEI'><ins id='dCNEI'></ins><ul id='dCNEI'></ul><sub id='dCNEI'></sub></form><legend id='dCNEI'></legend><bdo id='dCNEI'><pre id='dCNEI'><center id='dCNEI'></center></pre></bdo></b><th id='dCNEI'></th></span></q></dt></tr></i><div id='dCNEI'><tfoot id='dCNEI'></tfoot><dl id='dCNEI'><fieldset id='dCNEI'></fieldset></dl></div>

    <small id='dCNEI'></small><noframes id='dCNEI'>

        <bdo id='dCNEI'></bdo><ul id='dCNEI'></ul>
    1. <tfoot id='dCNEI'></tfoot>

    2. <legend id='dCNEI'><style id='dCNEI'><dir id='dCNEI'><q id='dCNEI'></q></dir></style></legend>

      1. 在 Drupal 中创建一个非常简单的表单

        时间:2023-06-22
      2. <legend id='w1v4h'><style id='w1v4h'><dir id='w1v4h'><q id='w1v4h'></q></dir></style></legend>

          <tfoot id='w1v4h'></tfoot>

          <small id='w1v4h'></small><noframes id='w1v4h'>

                <bdo id='w1v4h'></bdo><ul id='w1v4h'></ul>
                  <tbody id='w1v4h'></tbody>

                  <i id='w1v4h'><tr id='w1v4h'><dt id='w1v4h'><q id='w1v4h'><span id='w1v4h'><b id='w1v4h'><form id='w1v4h'><ins id='w1v4h'></ins><ul id='w1v4h'></ul><sub id='w1v4h'></sub></form><legend id='w1v4h'></legend><bdo id='w1v4h'><pre id='w1v4h'><center id='w1v4h'></center></pre></bdo></b><th id='w1v4h'></th></span></q></dt></tr></i><div id='w1v4h'><tfoot id='w1v4h'></tfoot><dl id='w1v4h'><fieldset id='w1v4h'></fieldset></dl></div>
                • 本文介绍了在 Drupal 中创建一个非常简单的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要做的就是有一个可以执行此操作的表单:

                  All I need to do is have a form that does this:

                  1. 用户在文本框中输入邮政编码
                  2. 提交后,用户被重定向到 mysite.com/[用户邮政编码]

                  就是这样!我知道验证等也是可取的,但我现在只需要让它工作.我不介意它是硬编码的还是使用 Drupal 表单 API(实际上我更喜欢前者!).

                  That's it! I know validation etc. would be desirable as well, but I just need to get this working for now. I don't mind if it's harcoded or utilises the Drupal form API (actually I'd prefer the former!).

                  我知道这很简单,但不幸的是我来自前端背景并且对这类事情有一些了解:(

                  I know this is dead simple, but unfortunately I'm coming from a front-end background and have a bit to learn about this sort of thing :(

                  干杯!

                  推荐答案

                  使用 Form API 和 自定义模块.您将使用 Form API 构建一个表单并添加一个提交处理程序,该处理程序将表单的重定向更改为您想要的任何内容.最后,您需要创建一种访问表单的方法(通过创建菜单项或通过创建块).

                  This is pretty easy with the Form API and a custom module. You'll build a form using the Form API and add a submit handler that changes the redirect for the form to whatever you'd like. Finally, you'll need to create a way to access the form (either by creating a menu item or by creating a block).

                  这是一个实现您想要的表单的示例:您需要仔细阅读表单 API 参考以查看构建表单时的所有选项.它还提供了两种访问表单的方式:

                  Here's an example that implements a form like you want: you'll want to peruse the Form API reference to see all the options you have when building a form. It also provides two ways to access the form:

                  1. 使用 hook_menu() 提供http://example.com/test
                  2. 上的表单页面
                  3. 使用 hook_block() 提供一个包含表单的块,您可以在块管理页面上添加和移动该表单.

                  示例代码:

                  // Form builder. Form ID = function name
                  function test_form($form_state) {
                  
                    $form['postcode'] = array(
                      '#type' => 'textfield',
                      '#title' => t('Postcode'),
                      '#size' => 10,
                      '#required' => TRUE,
                    );
                    $form['submit'] = array(
                      '#type' => 'submit',
                      '#value' => t('Go'),
                    );
                  
                    return $form;
                  }
                  
                  // Form submit handler. Default handler is formid_submit()
                  function test_form_submit($form, &$form_state) {
                    // Redirect the user to http://example.com/test/<Postcode> upon submit
                    $form_state['redirect'] = 'test/' . check_plain($form_state['values']['postcode']);
                  }
                  
                  // Implementation of hook_menu(): used to create a page for the form
                  function test_menu() {
                  
                    // Create a menu item for http://example.com/test that displays the form
                    $items['test'] = array(
                      'title' => 'Postcode form',
                      'page callback' => 'drupal_get_form',
                      'page arguments' => array('test_form'),
                      'access arguments' => array('access content'),
                      'type' => MENU_NORMAL_ITEM,
                    );
                  
                    return $items;
                  }
                  
                  // Implementation of hook_block(): used to create a movable block for the form
                  function test_block($op = 'list', $delta = 0, $edit = array()) {
                    switch ($op) {
                      case 'list': // Show block info on Site Building -> Blocks
                        $block['postcode']['info'] = t('Postcode form');
                        break;
                      case 'view':
                        switch ($delta) {
                          case 'postcode':
                            $block['subject'] = t('Postcode');
                            $block['content'] = drupal_get_form('test_form');
                            break;
                        }
                        break;
                    }
                  
                    return $block;
                  }
                  

                  更多信息:

                  • 创建模块 - 教程:Drupal 6.x
                  • 表单 API 快速入门指南
                  • 表单 API 参考
                  • hook_menu() API 参考
                  • hook_block() API 参考
                  • Drupal 6 中的 hook_block 示例
                  • Creating modules - a tutorial: Drupal 6.x
                  • Form API Quickstart Guide
                  • Form API Reference
                  • hook_menu() API reference
                  • hook_block() API reference
                  • Example of hook_block in Drupal 6

                  这篇关于在 Drupal 中创建一个非常简单的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Drupal 7 覆盖自定义主题中的 jquery js 文件 下一篇:Drupal 7 中用户的图片存储在哪里?

                  相关文章

                  1. <i id='QTyQ4'><tr id='QTyQ4'><dt id='QTyQ4'><q id='QTyQ4'><span id='QTyQ4'><b id='QTyQ4'><form id='QTyQ4'><ins id='QTyQ4'></ins><ul id='QTyQ4'></ul><sub id='QTyQ4'></sub></form><legend id='QTyQ4'></legend><bdo id='QTyQ4'><pre id='QTyQ4'><center id='QTyQ4'></center></pre></bdo></b><th id='QTyQ4'></th></span></q></dt></tr></i><div id='QTyQ4'><tfoot id='QTyQ4'></tfoot><dl id='QTyQ4'><fieldset id='QTyQ4'></fieldset></dl></div>
                    <legend id='QTyQ4'><style id='QTyQ4'><dir id='QTyQ4'><q id='QTyQ4'></q></dir></style></legend>

                    <small id='QTyQ4'></small><noframes id='QTyQ4'>

                    • <bdo id='QTyQ4'></bdo><ul id='QTyQ4'></ul>

                  2. <tfoot id='QTyQ4'></tfoot>