Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been doing a [back][next] to [finish] set of forms for user input fields, think of it like a questionnaire for user info where the user can still go back to the previous pages to update their info.. until it reaches the end of the pages to [finish]

I've done this before (hardcoded) but my code is too long and all the debugging gave me a headache. My first approach was:

  • Use a PHP case to find out which phase/step the user is in now
  • If the user clicks on [next], the page variable appends a +1 to the page count
  • If the user clicks on [back], the page var deducts -1 to the page count, until it reaches [finish]
  • If the user leaves the page for some reason and comes back to it, the session/cookie saved fills in the form values and which phase/step the user is in

This method of mine isn't very dynamic as the php case is hardcoded to a set of page numbers & phases, if the client wants to add another page; that can be a problem.

I'm new to Drupal; maybe Drupal already has some part of the API that makes this [back][update][next][finish] easier, or a easier way to store cookies? If by PHP only, is there a better approach?

share|improve this question

migrated from stackoverflow.com Apr 29 '11 at 7:20

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted

You should always use the Form API for forms, unless you really wanted to use the Webform module. The learning curve it steeper but you gain more maintainability (everything is in code from the start) and flexibility. You can create multisteps form with the API. See form_example_wizard.inc and Drupal 7 multistep forms using variable functions (also with Drupal 6) for examples. Another solution, is to use the CTools' wizard API.

share|improve this answer
The Examples project (drupal.org/project/examples) has a form example with multistep form demonstrations for D6 and D7. – rfay Apr 29 '11 at 13:14
+1 for CTools Wizard API – Alex May 1 '11 at 15:52

Try using the webform module like so: http://drupal.org/node/324779

share|improve this answer
+1 this will make it much easier. – Finbarr Apr 29 '11 at 1:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.