Answers.Body: <p>There are a bunch of ways to handle this.</p>
  
  <p>Before proceeding down this path, consider if Webform-CiviCRM integration (for Drupal) or Caldera Forms-CiviCRM integration (for WordPress) will work for you - it will save you a lot of work if so.</p>
  
  <p>If that's NOT an option, consider a) storing the data in the database (using the <code>postProcess</code> hook), b) storing the data in the <code>$_SESSION</code> variable, or c) using jQuery to fake having a multi-page form on a single page.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-19T15:19:24.767Z
Answers.Text: None of these seem to be really elegant. Is there no better way? I saw this kind of pattern (chained forms with "next" buttons) quite often in CiviCRM, and thought there was a "default" way of doing this. Thanks a lot for your answer anyway!
Answers.UserDisplayName: Pascal Wiesmann
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-19T15:26:59.063Z
Answers.Text: Can you give an example of such a form?  Most examples I can think of (e.g. contribution page workflow) store data in the db.  If you did this outside Civi, how would you store the data between forms?
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-19T15:30:09.137Z
Answers.Text: Option b) with the `$_SESSION` variable seems to be a nice and easy workaround. Do you have an idea of how I can achieve that the next form (e.g `step2`) is displayed after `step1` has postprocessed its input?
Answers.UserDisplayName: Pascal Wiesmann
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-19T15:33:18.897Z
Answers.Text: See here: https://forum.civicrm.org/index.php?topic=31729.0
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-19T16:12:57.620Z
Answers.Text: thanks for the link! And sorry, I did not see your other comment before submitting mine. A example would be in CiviRule, where there is a "next" button that leads to another form which allows to further specify the rule. Outside of civi I would not exactly store the data, but just pass it on to the next form. (using the `$_POST` - Variable)
Answers.UserDisplayName: Pascal Wiesmann
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-25T18:14:23.613Z
Answers.Text: For what its worth I used jQuery to 'fake' the multi-page form and it worked well for me. I've also used Webform CiviCRM for Drupal.
Answers.UserDisplayName: Zachary
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-19T14:52:02.307Z
Answers.LastActivityDate: 2017-07-19T14:52:02.307Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>If you're open to using AngularJS, I think you could use the <a href="https://github.com/civicrm/civicrm-core/blob/0b1991948184b8d6b4e290f8514406f7fd620c21/ang/crmUi.js#L750-L750" rel="nofollow noreferrer">crmUiWizard</a> directive, which is how CiviMail seems to create a multi-step form for building mailings.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-19T16:22:11.790Z
Answers.LastActivityDate: 2017-07-19T16:22:11.790Z
Answers.UserDisplayName: Sean
Body: <p>If I just had .php files I would do the following:
  <code>step1.php</code>'s submit button goes to <code>step2.php</code>. <code>step2.php</code>'s submit button goes to <code>step3.php</code>, etc.</p>
  
  <p>The problem is that I need data that the user entered in step1 in order to display step2. For step3 I need data from step2, etc.</p>
  
  <p>I tried creating multiple forms with <code>civix generate:form</code>, but how can I get data entered in previous steps?</p>
  
Tags: <extension><php>
Title: building an extension: how can I create a multiple-step form?
ThreadText: # building an extension: how can I create a multiple-step form?
  
  (Asked by: username_0 on 2017-07-19)
  
  If I just had .php files I would do the following:
  `step1.php`'s submit button goes to `step2.php`. `step2.php`'s submit button goes to `step3.php`, etc.
  
  The problem is that I need data that the user entered in step1 in order to display step2. For step3 I need data from step2, etc.
  
  I tried creating multiple forms with `civix generate:form`, but how can I get data entered in previous steps?
  
  **Tags:** extension, php
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-07-19. Score: 3
  
  There are a bunch of ways to handle this.
  
  Before proceeding down this path, consider if Webform-CiviCRM integration (for Drupal) or Caldera Forms-CiviCRM integration (for WordPress) will work for you - it will save you a lot of work if so.
  
  If that's NOT an option, consider a) storing the data in the database (using the `postProcess` hook), b) storing the data in the `$_SESSION` variable, or c) using jQuery to fake having a multi-page form on a single page.
  
  > **Comments:**
  > **username_0**: None of these seem to be really elegant. Is there no better way? I saw this kind of pattern (chained forms with "next" buttons) quite often in CiviCRM, and thought there was a "default" way of doing this. Thanks a lot for your answer anyway!  
  > **username_1**: Can you give an example of such a form?  Most examples I can think of (e.g. contribution page workflow) store data in the db.  If you did this outside Civi, how would you store the data between forms?  
  > **username_0**: Option b) with the `$_SESSION` variable seems to be a nice and easy workaround. Do you have an idea of how I can achieve that the next form (e.g `step2`) is displayed after `step1` has postprocessed its input?  
  > **username_1**: See here: https://forum.civicrm.org/index.php?topic=31729.0  
  > **username_0**: thanks for the link! And sorry, I did not see your other comment before submitting mine. A example would be in CiviRule, where there is a "next" button that leads to another form which allows to further specify the rule. Outside of civi I would not exactly store the data, but just pass it on to the next form. (using the `$_POST` - Variable)  
  > **username_2**: For what its worth I used jQuery to 'fake' the multi-page form and it worked well for me. I've also used Webform CiviCRM for Drupal.  
  
  ---
  
  ### Answer by username_3 on 2017-07-19. Score: 3
  
  If you're open to using AngularJS, I think you could use the [crmUiWizard](https://github.com/civicrm/civicrm-core/blob/0b1991948184b8d6b4e290f8514406f7fd620c21/ang/crmUi.js#L750-L750) directive, which is how CiviMail seems to create a multi-step form for building mailings.
  
  
  ---
  
  