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?

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.

  • 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! – Pascal Wiesmann Jul 19 '17 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? – Jon G - Megaphone Tech Jul 19 '17 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? – Pascal Wiesmann Jul 19 '17 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 '17 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, privacy policy and cookie policy

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