0

I am building a multiple steps registration form. I will only allow the user to progress to next step when the current step is fully validated. I will also store all the information in the session and when I have everything I will persist it to the database.

My steps will involve different fields like: user details with address, business details and that will have address fields as well, and then a few other fields. However some users will need to fill in the address while other won't be required.

  1. UserDetailsRequest (without including addresses)
  2. BusinessDetailsRequest (without including addresses)
  3. AddressRequest
  4. ExtraFieldsRequest

OR

  1. UserDetailsRequest (with addresses)
  2. BusinessDetailsRequest (with addresses)
  3. ExtraFieldsRequest

Can I combine the requests in my controller depending on the user type and if they are required to provide an address?

In general, do I need to create as many requests as I have forms on my project? Can I instead create a 'bigger' form request and put some logic in it?

Cristian
  • 2,390
  • 6
  • 27
  • 40
  • Sure you can, but that might cause an overhead for maintaining such a code, because best practices suggest keeping the methods shorter then 20 lines of code. – naneri Sep 12 '15 at 07:49

1 Answers1

0

Starting tip: First of all, if the addresses are related to two separate entities, I would not separate everything to create the third "Addresses" wizard step. It could result confusing in terms of user experience. Instead, I would prefer the second solution you proposed, the one with three steps.

Now, about the wizard and storing data. You can do it in many ways, of course. Obviously you could use sessions, but if you don't know how your application will scale in future you could find yourself in some troubles. I would do something different.

Like this:

  • use some library or framework (jQuery, Angular, both, you choose) to make a single page app for your wizard. It will be cleaner and also more usable if your user wants to go back, edit something and so on;
  • create a javascript object with all the data you need and then send it to a controller, where it will be checked, validated and then processed. Obviously you will create classes accordingly;

I don't like to use sessions. If I can choose to not use them, I always enjoy it in the long term.