1

I have a need for 2 different login forms: customers and professionals. Each login form is slightly different in markup and heading and has different linkages to the registrations form(s) if a visitor (customer or pro) has not been registered yet.

What I've seen so-far is that only one form can be used: /login.

A solution might be to add a query string to the login link, like /login?pro and then based on the query string filter the right form content.

{% if craft.app.request.queryString('login') == 'pro' %} do something {% endif %}

Any thoughts or suggestions would be welcome?

1
  • Is there anything in particular that's not working for you? If the only problem is how to route different login URLs to the same template, you can use custom routes for that, see my answer below.
    – MoritzLost
    Commented Sep 14, 2021 at 14:42

1 Answer 1

1

You can either use the same form or two different forms with separate URLs. Craft doesn't really care where your login form submission comes from, it's handed off to the same controller regardless. Which approach is better depends on how much your forms differ and how you prefer to write your templates. For the single-form approach, you can use a URL parameter to check the form 'type' and modify the template based on that (as in your example). Or use two completely separate forms with their own templates.

The only thing Craft 'knows' about your login URL is the loginPath config setting. But you're not limited to that, you can point any path to your login form template(s) using custom routes, so you can pretty much do whatever you want in terms of offering different login forms.

One thing that might trip you up is that Craft's controllers use the loginPath setting to determine where to redirect users that are trying to perform an action that requires login, as well as the redirect for the {% requireLogin %} tag. Two possible solutions to that:

  • Instead of hard-coding the value, you can set the loginPath to a callback that returns the login path based on the current session / request. You can use this to dynamically change which login form users get redirected to for certain actions / in certain situations.
  • You could also just not use the {% requirePermission %} tag and make sure that in your 'normal' user flow the user logs in before trying to execute an action that will redirect to the login page automatically.
  • In both login forms, add links to switch between the two different forms so users can find the correct form for them if they end up on the wrong one.
1
  • 1
    Thank you for your feedback. Wasn't clear you could use different login forms because of the (limitations of) loginPath settings. Commented Sep 15, 2021 at 8:33

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.