【问题标题】:Another save button on node form节点表单上的另一个保存按钮
【发布时间】:2013-01-07 09:32:27
【问题描述】:

我想添加一个按钮“保存并添加更多”到节点添加表单 drupal 6。 单击此按钮页面应在保存节点后重定向到相同的节点添加表单。 我有一个内容类型的孩子要添加孩子,用户可能有多个孩子,所以如果他/她想添加另一个孩子,他/她将点击“保存并添加更多”,用户只有一个孩子,他/她将点击关于“保存” 所以基本上只有重定向是改变新按钮。

【问题讨论】:

    标签: drupal-6 cck


    【解决方案1】:

    您需要创建一个包含两个文件的简单模块来执行此操作。在您的 /sites/all/modules/custom 文件夹中创建一个新目录“addmore”(如果该文件夹不存在,则创建该文件夹)并在该目录中创建以下文件:

    • 添加更多信息
    • addmore.module

    addmore.info 的内容:

    name = "Add More"
    description = Create and Add More button on Child node forms
    package = Other
    core = 6.x
    

    addmore.module的内容 (假设“Child”内容类型的机器名是“child”)

    <?php
    /**
     * Implementation of HOOK_form_alter
     *
     * For 'child' node forms, add a new button to the bottons array that submits
     * and saves the node, but redirects to the node/add/child form instead of to
     * the newly created node.
     */
    function addmore_form_alter(&$form, $form_state, $form_id) {
      if ($form_id == 'child_node_form') {
        $form['buttons']['save_and_add_more'] = array(
          '#type' => 'submit',
          '#value' => t('Save and add more'),
          '#weight' => 20,
          '#submit' => array(
            // Adds the existing form submit function from the regular "Save" button
            $form['buttons']['submit']['#submit'][0],
            // Add our custom function which will redirect to the node/add/child form
            'addmore_add_another',
          ),
        );
      }
    }
    
    /**
     * Custom function called when a user saves a "child" node using the "Save and
     * add more" button. Directs users to node/add/child instead of the newly
     * created node.
     */
    function addmore_add_another() {
      drupal_goto('node/add/child');
    }
    

    创建这些文件后,导航到您的模块页面并启用“添加更多”模块。

    就是这样。您将看到一个新的“保存并添加更多”按钮,该按钮仅在创建子节点和编辑表单时执行此操作。

    【讨论】:

      猜你喜欢
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多