Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
neelraina
5,587 PointsIf it possible to create a multi-level registration process?
I was wondering if it was possible to create a registration to a membership site with different roles assigned. For example, I am designing a site that will manage both the clients and employees of a small business. The business works mainly with freelancers, has a high turnover, and these workers are usually recommended by other people who have freelanced for the business.
I was thinking of having a registration form that - along with the usual data fields of name, username, password and email- includes a drop-down menu/radio button option of 'client' or 'freelancer'. And depending on which is chosen when the user creates the account, that user will be given either a client profile or an employee one. As you can imagine, they will be significantly different.
Can this be done? If anyone could point me in the right direction that would be awesome!
2 Answers
Kevin Korte
28,149 PointsSure it's possible, there will be a lot of server side logic to handle it. I'd start to look at some MVC frameworks like Laravel if you want to stay in PHP, that will help you with user accounts and routing.
neelraina
5,587 PointsThanks Kevin - I had no idea a user could could manipulate JQuery like that. Then again, I have minimal knowledge of Javascript.
I just saw things like this, https://scotch.io/tutorials/angularjs-multi-step-form-using-ui-router, where he used Angular JS. And in Laracasts, Jeffrey Way did a tutorial with angular. I guess that tilted my head towards client-side functionality.
But after reading your post I will make plans to build the majority of actions on the server side.
Kevin Korte
28,149 PointsYeah, for a rule of thumb, anything on the client side can be viewed and edited by the client. Angular is a bit different being a framework
You could use angular here, to collect the data as you go. You'd still need to send it to a backend if you wanted the data to persist, but Angular certainly can be used to help you accomplish what you're after.
There are multiple ways to do this. If you feel like giving Angular a shot, go for it! Just remember to never trust validations or data coming from the client side (javascript), always validate and sanitize on the server side regardless.
neelraina
5,587 Pointsneelraina
5,587 PointsThanks Kevin, I'm actually building it in Laravel! I guess my issue is in regards to the JQuery needed on the registration form.
Kevin Korte
28,149 PointsKevin Korte
28,149 PointsWhat jQuery is needed? Validation?
If it were me, I'd have the same form, post to the same location. Get all your form data, and first thing to do is check with php if the user is registering as a client or freelancer.
Depending on that check, you can write a conditional to finish the registration process. You'll than want to store in a database if they are a client or freelancer, and later use that check against the database to decide which profile to show them.
All of this should be done server side. A couple things with jQuery. If a user has javascript disabled, none of the form logic written in jQuery will work. Also know that jQuery is client side, many any user, and manipulate your jQuery code to do or allow whatever they want, before they post the form, meaning they can easily change your logic.
jQuery with forms is a great enhancement tool, but try to avoid writing any logic with it is critical to the site working.