Drupal 6 节点窗体上的另一个保存按钮

Drupal 6 节点窗体上的另一个保存按钮,drupal-6,cck,Drupal 6,Cck,我想添加一个按钮“保存并添加更多””到节点添加表单drupal 6。 单击此按钮,保存节点后,页面应重定向到同一节点添加表单。 我有一个要添加的内容类型子项,用户可能有多个子项,因此如果他/她想添加另一个子项,他/她将单击“保存并添加更多”,而用户只有一个子项,他/她将单击“保存” 因此,基本上,只需更改新按钮的重定向。您需要创建一个包含两个文件的简单模块来完成此操作。在/sites/all/modules/custom文件夹中创建一个新目录“addmore”(如果该文件夹不存在,则创建该文件夹

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

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

  • addmore.info
  • 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');
}