Prokop
Prokop

Reputation: 35

Drupal 7 convert node form add to multi step form

I have a node type with fields, some required, some not. I'm tring to do a multi step form of the node form create. Required fields are the first step and remainings is the next one.

I hide the fields not needed in the first step, with hook_form_alter, thats the easy part, but I don't know how to convert the form to multi step form. I read the API doc, which says, that I have to use

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

this is how drupal knows that this is a multi-step form. but if I understand it correctly, I cannot use this in hook_form_alter since the $form is not in that state there.

Where can I remove submit and add next to the form ?

Thanks for the help.

Upvotes: 1

Views: 3575

Answers (2)

Keigan
Keigan

Reputation: 16

hook_form_alter (or hook_form_FORM_ID_alter) is what you want to use, you just have to make sure that your event fires last. To do that, you can go into your database and increase the weight of your module in the system table (or write a db_update, which is the long way).

A lot of Drupal developers create a module called "Overrides" or something similar, which always fires last. You could put your override in there.

As a side note to your project, you might want to look into Ctools and the form_wizard functionality included with it. Could be very useful if you ever want to place your wizard in a modal. I've found it to be very superior to mforms, but it requires a little bit of familiarity.

Good luck!

Upvotes: 0

Try http://drupal.org/project/mforms and http://drupal.org/project/multistep as a Guidance. The module is basically for making a easy multi step form

Some snippet,

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.

Upvotes: 2

Related Questions