views:

24

answers:

1

Hi, I am in a bit of a dilemma about how best to handle the following situation. I have a long registration process on a site, where there are around 10 form sections to fill in. Some of these forms relate specifically to the user and their own personal data, while most of them relate to the user's pets - my current set up handles user specific forms in a User_Controller (e.g via methods like user/profile, user/household etc), and similarly the pet related forms are handled in a Pet_Controller (e.g pet/health). Whether or not all of these methods should be combined into a single Registration_Controller, I'm not sure - I'm open to any advice on that.

Anyway, my main issue is that I want to generate a progress bar which shows how far along in the registration process each user is. As the urls in each form section can potentially be mapping to different controllers, I'm trying to find a clean way to extract which stage a person is at in the overall process. I could just use the query string to pass a stage parameter with each request, e.g user/profile?stage=1. Another way to do it potentially is to use routing - e.g the urls for each section of the form could be set up to be registration/stage/1, registration/stage/2 - then i could just map these urls to the appropriate controller/method behind the scenes.

If this makes any sense at all, does anyone have any advice for me?

A: 

I think creating a SignupController is a fine idea. The initial user registration is a distinct process, and ought to be separate from general profile management tasks.

If you've been a good developer and keeping your controllers thin and your models fat, you ought to be able to avoid any code duplication. If you find yourself duplicating, it's probably a good idea to think about refactoring.

As a concrete example, consider your user's email address. Let's say you're pretty strict, and any time a user changes their email address, they have to do a little confirmation-email dance. During signup, you'll want the user to return to the signup process after they click their confirmation link. When an existing user is changing their email address, you'll want them to land somewhere else (like their profile). It's likely that you'll want different content in the body of the confirmation email is each case. Trying to make /user/profile handle both cases is going to start creating a bunch of complexity where the action needs to figure out context and behave accordingly.

The better solution is to decide that signup is it's own mode of interaction, distinct from general profile management. Therefore, it gets its own controller, which shares model and view resources with other controllers.

That's my take, anyway.

timdev
Hi Tim, my models do handle validation/db interaction. Agree about having a Registration Controller - all the forms are related, even though they interact with different models - from an OO perspective, models represent my data as objects, I don't need my controllers to do this as well. The only issue is that as well as the registration forms, there will also be ongoing forms which will be similar. This may involve some duplication of code, but the flexibility of separating out the ongoing forms from the registration ones into different controllers will be of benefit - does that make sense?
chrisj
Yes, forms can be a hassle. Depending on your framework, you might be able to factor things out nicely. I use Zend_Form quite frequently, which is nice, because you can use composition to modify things as needed. So you have a form class that represents the form in it's "natural" state, but if you need a special-purpose version, you just instantiate the "natural" one, then add/remove/change bits of it. If your forms are just straight HTML in templates, you'll probably end up repeating yourself somewhat. You can try to get clever about it, but doing it "right" depends on your framework
timdev