I'm writing a customised login form which incorporates both the default login email & password, but also a "pre registration" form which asks the user for an email address. This then gets validated, and if it passes (e.g. doesn't already exist, can receive email, etc) they get dispatched to the proper registration page.
The problem I'm having is that if validation fails, the user is returned to the login page with an appropriate error message, but the email address input text box is not populated with the email address they previously entered.
At the moment my login page source looks like this:
<label for="regemail" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label> <div class="input-box"> <input type="text" name="regemail" value="<?php echo $this->escapeHtml($this->getRegemail()) ?>" id="regemail" class="input-text required-entry validate-email" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Email Address')) ?>" /> </div>
I haven't created a "getRegemail" property/function, none of the guides I've seen about adding custom fields to customer registration define "getMyCustomField", so I presume something makes this work?
getUsername() works on the original login form, even though the form field is called "login[username]", so I guess I'm missing a piece of the puzzle. For example - when you try and log in with the wrong password, you get returned to the login page but with the email address you entered already populated.
The problem I've got is that when the form is submitted - and validation fails - the user is returned to the login page by my controller indexAction, but the "regemail" field is not populated - i.e.
What am I doing wrong here? It feels like it should be something obvious but I'm not getting it
Thanks in advance.
Solved! Go to Solution.
Has you created the attribute for customers or is just the html field?
In the original form the fields values are stored in the current session (I don't remember exactly but in adminhtml there is something like formData. Is a session with the form values so that's how you can populate the form again after a fail.
I guess you should explore that part to be able to maintain your custom value on session (as the others values).
If you get the value into the session first you should be able to use the magic getter.
I mean you shoul dbe able to use ->getYourfield()
In the same way you're using ->getUsername()
Managed to solve this, thanks.
As you pointed out - on the core login controller (AccountController.php) the email the user enters is saved in the session via:
..and then recovered on login.phtml via Mage/Customer/Block/Form/Login.php using
I approximated this without extending the Block code by using:
<input type="text" name="reg-email" value="<?php echo $this->escapeHtml(Mage::getSingleton('customer/session')->getPreRegEmail(true)) ?>" id="reg-email" class="input-text required-entry validate-email" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Email Address')) ?>" />
..after having saved the email the user entered in my custom controller with:
Thanks for the pointers in the right direction!