I am building a plugin. What is the right way to "paginate" forms? I have a form that need to be posted, and depending of the data posted I need to show one or another form.
Currently I have a class "user_form" and a script "index.php" that instantiate the "user_form" and deal with the post data. It's working.
Now I need to show another form to the user depending of the posted data.
I was thinking in doing the following, but I don't know if this is the "moodle way":
1. Create one class for each form
2. Instantiate one or another form in index.php
3. MY QUESTION: How to identify which form to instantiate for each step? Checking the posted data before instantiate the form class?
OR maybe there is a better way to do that.
Thank you.
There's a few ways to achieve this, but I would suggest that you process each form, then redirect to a new URL that displays the next form based on the data submitted in the previous one. This keeps the requests that change stuff based on the submitted data as POSTs, and the requests that are displaying pages as GETs, and avoids accidental duplicate submission if the user reloads the page.
If you need to pass data submitted to one form into another, it can be stored in the database, stored in the user's session, or passed in a URL parameter as appropriate.