Drupal 多步节点表单如果不在最后一步则阻止保存

发布于 2024-11-03 08:06:29 字数 2236 浏览 1 评论 0原文

尝试将特定内容类型的节点/添加表单更改为多步骤表单。

(drupal6, cck dev 3x (for multigroup))

我无法理解的是如何防止表单在步骤 1 提交时实际创建节点并过渡到步骤 2。

现在步骤 2 不可能,但我不知道如何阻止保存。

我已经尝试过以下操作:

放置 $form["#submit"] = array() 然后添加我的 ["#submit"] 处理程序(这不起作用,它仍然会被保存)

也尝试过只返回空白但仍然会导致节点被保存。

* HOOK FORM ALTER */
  function armormod_form_alter(&$form, $form_state, $form_id) {
  //print_r($form);
  //print_r($form_state);
  //print_r($form_id);

  if($form_id = "seed_node_form") {

  //set the default step
  if(!isSet($form_state["storage"]["step"])) {
     $form_state["storage"]["step"] = 1;
  }

  // Add an after_build function to process when everything's complete.
  $form['#after_build'][] = 'armormod_after_build';
    /* clear the submit (this doesn't  work)
        Normally calls menu_node_form_submit and then upload_node_form_submit
    */
    //$form["#submit"] = array();
  $form["#submit"][] = "armormod_submit";
  $form["#validate"][] = "armormod_validate";

  }


  }

  function armormod_submit($form, &$form_state) {

if($form["form_id"]["#value"] == "seed_node_form") {
    if($form_state["storage"]["step"] < 2) {
        drupal_set_message("Form Step:".$form_state["storage"]["step"]);
        return;
    }
   } else {

    return $form;
   }

  }

  function armormod_validate($form, &$form_state) {

if($form["form_id"]["#value"] == "seed_node_form") {
    drupal_set_message(t("Validation Called"), "status");
    return;
} else {

    return $form;
}

  }

  /* AFTER BUILD LETS US MODIFY CCK FORM ELEMENTS */

  function armormod_after_build($form, &$form_state) {

  if($form["form_id"]["#value"] == "seed_node_form") {

    if($form_state["storage"]["step"] == 2) {
        drupal_set_message(t("Step 2 Build Called"), "status");
        $form["group_statistics"]["#access"] = 1;
        $form["buttons"]["submit"]["#value"] = "Save";

    } else {
        drupal_set_message(t("After Build Called"), "status");

        //hide statistics group
        $form["group_statistics"]["#access"] = false;
        $form["buttons"]["submit"]["#value"] = "Next Step";
        unset($form["buttons"]["preview"]);
        //print_r($form);
    }
} 
return $form;

}

Trying to change the node/add form for a specific content type to a multistep form.

(drupal6, cck dev 3x (for multigroup) )

What I can't wrap my head around is how to prevent the form from actually creating a node on the step 1 submission and transition to step 2.

No possibility of step being 2 right now, but I can't figure out how to prevent the save.

I have tried the following:

putting $form["#submit"] = array() and then adding my ["#submit"] handler (this doesn't work, it still gets saved)

Have also tried just blank returns which fire but still cause the node to be saved.

* HOOK FORM ALTER */
  function armormod_form_alter(&$form, $form_state, $form_id) {
  //print_r($form);
  //print_r($form_state);
  //print_r($form_id);

  if($form_id = "seed_node_form") {

  //set the default step
  if(!isSet($form_state["storage"]["step"])) {
     $form_state["storage"]["step"] = 1;
  }

  // Add an after_build function to process when everything's complete.
  $form['#after_build'][] = 'armormod_after_build';
    /* clear the submit (this doesn't  work)
        Normally calls menu_node_form_submit and then upload_node_form_submit
    */
    //$form["#submit"] = array();
  $form["#submit"][] = "armormod_submit";
  $form["#validate"][] = "armormod_validate";

  }


  }

  function armormod_submit($form, &$form_state) {

if($form["form_id"]["#value"] == "seed_node_form") {
    if($form_state["storage"]["step"] < 2) {
        drupal_set_message("Form Step:".$form_state["storage"]["step"]);
        return;
    }
   } else {

    return $form;
   }

  }

  function armormod_validate($form, &$form_state) {

if($form["form_id"]["#value"] == "seed_node_form") {
    drupal_set_message(t("Validation Called"), "status");
    return;
} else {

    return $form;
}

  }

  /* AFTER BUILD LETS US MODIFY CCK FORM ELEMENTS */

  function armormod_after_build($form, &$form_state) {

  if($form["form_id"]["#value"] == "seed_node_form") {

    if($form_state["storage"]["step"] == 2) {
        drupal_set_message(t("Step 2 Build Called"), "status");
        $form["group_statistics"]["#access"] = 1;
        $form["buttons"]["submit"]["#value"] = "Save";

    } else {
        drupal_set_message(t("After Build Called"), "status");

        //hide statistics group
        $form["group_statistics"]["#access"] = false;
        $form["buttons"]["submit"]["#value"] = "Next Step";
        unset($form["buttons"]["preview"]);
        //print_r($form);
    }
} 
return $form;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

养猫人 2024-11-10 08:06:29

尝试为“下一步”功能添加一个单独的提交按钮及其自己的提交处理程序。

$form['button']['next'] = array(
  '#type' => 'submit',
  '#value' => t('Next Step'),
  '#submit' => array('armormod_next_step_submit'),
);

function armormod_next_step_submit($form, &$form_state) {
  // Do your Next Step stuff here
}

Try adding a separate submit button with its own submit handler for the "Next Step " functionality.

$form['button']['next'] = array(
  '#type' => 'submit',
  '#value' => t('Next Step'),
  '#submit' => array('armormod_next_step_submit'),
);

function armormod_next_step_submit($form, &$form_state) {
  // Do your Next Step stuff here
}
冷情妓 2024-11-10 08:06:29

有一个模块可以实现这一点,除非您真的想开发自己的解决方案,否则我建议您使用 Multistep 模块。有关此模块的更多详细信息(来自其项目页面):

Multistep 向内容类型编辑表单添加了多步骤功能。它通过为内容类型中的每个字段组分配一个步骤编号并隐藏所有不属于当前步骤的组来实现此目的。然后,用户可以使用不同的提交按钮来重定向到上一个、下一个或当前步骤。

该模块还为每种内容类型提供了一个块,其中包含该表单中不同组的菜单和一个进度栏。这提供了一种简单的方法来跳转到整个表单中的不同步骤,而无需逐一进行,并跟踪表单的进度。

There is a module for that, unless you really want to develop your own solution, I recommend you to use the Multistep module. Some more details about this module (from its project page):

Multistep adds multiple-step functionality to content type editing forms. It does so by assigning a step number to each fieldgroup within the content type and hiding all the groups that do not belong to the current step. The user can then use different submitting buttons that will redirect to the previous, next, or current step.

The module also provides a block for each content type with a menu of the different groups within that form and a progress bar. This provides an easy way to jump to different steps throughout the form without having to go one by one and to keep track of you progress through the form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文