HowTo: adding the registration form to the login page
When I started ZenMagick I had the requirement to split the login and registration page. That wasn’t too hard as there were already two separate templates. Getting the controller code to work properly was much harder, though.
Still, there are folks that would like to keep it the way it was, so here is how it can easily be done:
The first step is to include the registration form in login.php. The easiest way is the one-liner:
<?php include('create_account.php') ?>
at the bottom of login.php.
If you now try the login page you’ll see that it actually breaks. The reason for this is that create_account.php expects the objects $zm_account and $zm_address in the request.
So, the second step is to create a custom login controller that initalises empty instances of ZMAccount and ZMAddress, respectively. The new class file LoginController.php should be placed in the theme’s extra folder.
A very minimal version (no comments, bad indentation) would look similar to this:
class LoginController extends ZMLoginController {
function __construct() {
parent::__construct();
}
function ZMLoginController() {
$this->__construct();
}
function processGet() {
$account =& $this->create(“Account”);
$account->populate();
$address =& $this->create(“Address”);
$address->populate();
$this->exportGlobal(“zm_account”, $account);
$this->exportGlobal(“zm_address”, $address);
return parent::processGet();
}
}
So, what we are doing here is overriding the the controller’s processGet() method in order to add the missing objects to the templates environment. That way the template can use them to populate the form (with the initially empty values).
Everything else works as before. If the server side validation fails, the form returned is actually the original create_account.php form. This is in line with the current behavior of zen-cart.
Done!
