XF 2.0 Best practice for implementing the login & registration forms on a single page

DragonByte Tech

Well-known member
For my eCommerce tool, I plan to support guests adding products to the cart, and for them to be offered the login and registration forms upon clicking checkout. Ideally, I would want to preserve compatibility with 3rd party modifications that may modify the existing login or registration forms.

My initial thoughts are to include the login and register_form templates, while copying the actionIndex code from the Login and Registration controllers.

Is there a better way to achieve this?


Fillip
 
I believe you can specify a redirect URL with XenForo's default login, just using that and setting the action on the form to go to xenforo/login/login should be enough, I'd guess
 
I believe you can specify a redirect URL with XenForo's default login, just using that and setting the action on the form to go to xenforo/login/login should be enough, I'd guess
As far as I can tell, you don't need to, as XF uses the referrer header to redirect back to the page the user was at, so they should be redirected back assuming the registration or login went without error.

I was more wondering whether there were better ways of implementing them, as adding two include statements like that seems a bit hackish :P


Fillip
 
At face value, this works:

HTML:
<xf:breadcrumb href="{{ link('dbtech-ecommerce/checkout') }}">{{ phrase('dbtech_ecommerce_checkout') }}</xf:breadcrumb>

<xf:include template="login">
    <xf:set var="$xf.options.registrationSetup.enabled" value="0" />
</xf:include>

<div class="blocks-textJoiner"><span></span><em>{{ phrase('or_separator') }}</em><span></span></div>

<xf:include template="register_form" />

<xf:title>{{ phrase('dbtech_ecommerce_login_or_register') }}</xf:title>

I force $xf.options.registrationSetup.enabled off because the registration form is already there, and my own title ends up in the bottom of the template because those two templates have their own title tags.

I've not tested the actions themselves just yet.


Fillip
 
As far as I can tell, you don't need to, as XF uses the referrer header to redirect back to the page the user was at, so they should be redirected back assuming the registration or login went without error.

I was more wondering whether there were better ways of implementing them, as adding two include statements like that seems a bit hackish :p


Fillip

I might be missing some context, why would you need two include statements? Just need to instantiate the XenForo framework (which I assume you're already doing). That'll give you access to pretty much anything you need, XF's login process will handle the rest so you'll probably just need the form with the CSRF token
 
I might be missing some context, why would you need two include statements? Just need to instantiate the XenForo framework (which I assume you're already doing). That'll give you access to pretty much anything you need, XF's login process will handle the rest so you'll probably just need the form with the CSRF token
This isn't a 3rd party page :p

1518722907517.webp

Guest adds an item from our eCommerce store (fully native XF2 code) to cart -> clicks Checkout in a menu item that is not yet available -> receives that page in order to create an account or log in before they can proceed with checkout.

I'm reducing the barrier to entry by allowing potential customers to add items to cart before they have an account, so that they will be more committed to purchasing and see the creation of an account as less of a roadblock than if you required registration prior to adding items to cart.

Does that make more sense? :)


Fillip
 
Back
Top Bottom