Drupal 多步节点表单如果不在最后一步则阻止保存
尝试将特定内容类型的节点/添加表单更改为多步骤表单。
(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试为“下一步”功能添加一个单独的提交按钮及其自己的提交处理程序。
Try adding a separate submit button with its own submit handler for the "Next Step " functionality.
有一个模块可以实现这一点,除非您真的想开发自己的解决方案,否则我建议您使用 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):