I'm using the Form API in a custom module to collect a large amount of user data, which is then collated and assessed to provide an output.

Currently I'm using ajax to refresh the form and display the output when the user submits the form. Should I be displaying the results in a different manner, or is it perfectly reasonable to do it in this manner?

Say for example I have a Myers-Briggs type survey. The user would answer a long string of questions, which on submission, I then collate and redisplay the form with results, links to other content, relevant articles etc (not just a simple result).

Is this too heavy use of the Form API to provide content, or is it reasonable for a performance and development standpoint to do it this way?


$form['results']['#markup] = '<my markup>'
  • It's fine to use it in this way. Generally the way I determine whether to output the results as the final step of the form process or on a separate page, is to look at whether or not I want to be able to link to the results page. If yes, then a separate page is better. If no, then the end of the form process is fine.
    – Jaypan
    Dec 20, 2016 at 11:06
  • Hey, what is the exact question you are asking?
    – leymannx
    Dec 20, 2016 at 11:48
  • Thanks @Jaypan - I've actually been using your ajax form example from your website as a starting point!
    – Simo
    Dec 20, 2016 at 22:48
  • @leymannx - does the added line help clarify?
    – Simo
    Dec 20, 2016 at 22:49
  • Glad to hear Simo!
    – Jaypan
    Dec 20, 2016 at 23:33

1 Answer 1


I think its totally fine to do what you want with Form API. I once did something similar for a personality test module. On the final submit the node gets reloaded but this time in a different view mode to provide the results. If I remember it right I got inspired by Drupal's poll module which uses/used this view mode approach. By that you have both parts divided a little bit better - logically and performance related. Could that work for you?

  • Thanks @leymannx - I'll have a squiz at how you put your module together. I'm quite handy with the Form API, so for me it's also a question of whether it's worth the trouble doing things differently (and learning how to), or whether it's fine as is. That being said, my form is iterative, so you can go back and change things (it's not actually a personality test), so Form API all the way also makes sense.
    – Simo
    Dec 21, 2016 at 0:29
  • @Simo A multistep AJAX form that's nice! The idea then is to reload the page on the final submit of the form. At this point you'ld have the user inputs processed and take them - together with possible other content - to get displayed. And maybe a different view mode could be the thing where everything gets divided at.
    – leymannx
    Dec 21, 2016 at 6:43
  • So you'ld have a back and forth button of course and at the last step you'ld display a final submit button.
    – leymannx
    Dec 21, 2016 at 6:59

Your Answer

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

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