2

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?

2 Answers 2

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.

6
  • 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! Jul 19, 2017 at 15:19
  • 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? Jul 19, 2017 at 15:26
  • 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? Jul 19, 2017 at 15:30
  • 1
  • 1
    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.
    – Zachary
    Jul 25, 2017 at 18:14
3

If you're open to using AngularJS, I think you could use the crmUiWizard directive, which is how CiviMail seems to create a multi-step form for building mailings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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