Drupal Multistep Node Form Prevent Save If not on last step
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 开发者_如何学GoLETS 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;
}
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
}
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.
精彩评论