5

I'm new with Magento and I have a problem creating a new account in a Magento 1.7.0. When I input name, email and password and I click in create account it just refreshes the page.

So, I guess, it detect an error and redirects to the same page. First, I don't know which method is being called to register a new customer. I have changed app/code/core/Mage/Customer/controllers/AccountController.php so:

 /**
 * Create customer account action
 */
public function createPostAction()
{
    Mage::log('create post action', null, 'createAccount.log');
    if (!$this->_validateFormKey()) {
        $this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true)));
        return;
    }
    Mage::log('validateFormKey() returns true', null, 'createAccount.log');

I thought that _validateFormKey() was returning false and it was redirecting. But createAccount.log file is not being created. So... How can I know which method is being called to create a new user? It would be the first step to detect the error.

I have to say that some days ago I installed the SUPEE-6788 patch, which updated this AccountController.php file.

10

I guess the problem is that you have also rewritten the customer/form/register.phtml file in your template.

Those templates have been changed by SUPEE-6788.

app/design/frontend/base/default/template/customer/form/register.phtml
app/design/frontend/base/default/template/customer/form/resetforgottenpassword.phtml
app/design/frontend/base/default/template/persistent/customer/form/register.phtml
app/design/frontend/rwd/default/template/customer/form/resetforgottenpassword.phtml
app/design/frontend/rwd/default/template/persistent/customer/form/register.phtml
app/design/frontend/rwd/enterprise/template/customer/form/register.phtml
app/design/frontend/rwd/enterprise/template/persistent/customer/form/register.phtml

A git diff on the following file shows that there was a form key added:

--- a/app/design/frontend/base/default/template/customer/form/register.phtml
+++ b/app/design/frontend/base/default/template/customer/form/register.phtml
@@ -43,6 +43,7 @@
         <div class="fieldset">
             <input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
             <input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
+            <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
             <h2 class="legend"><?php echo $this->__('Personal Information') ?></h2>
             <ul class="form-list">
                 <li class="fields">

What do do?

Edit the customer/form/register.phtml in your template and add the form_key input field.

  • Thank you Anna, great answer, but register.phtml already have that line. – Jon Zangitu Dec 10 '15 at 12:26
  • The form key was the missing piece for my custom form. Thank you! – adprocas Jul 22 '16 at 19:59
  • Iam getting "Incorrect Captcha" error – Nadh May 25 '17 at 15:07
4

After upgrading your Magento to 1.9.2.2, or installing security patch SUPEE-6788, it may happen that your customer not able to register themselves. After filling in the registration form and submitting it, the page only refreshes without creating a customer account and without any error message shown.

From Magento 1.9.2.2 or from the security patch SUPEE-6788,magento added a hidden form field with the form_key to the registration form:

<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />

If the form_key field is not present in the registration file the form will not be processed.so since you are using the register.phtml from the custom theme so the upgradation of the magento 1.9.2.2. or installing security patch SUPEE-6788 will not add the form_key field in your custom theme file which results into the just refreshing the registration page wihout creating the customer.

Solution is add the <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" /> code to the register.phtml file after open tag used in your custom theme for your shop.

after adding the form key your registration.phtml will look like the below code

<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
<div class="fieldset">
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" /> <!-- added -->
2
app/design/frontend/yourtheme/default/template/persistent/customer/form/register.phtml 

in this file add these after form action.

    <?php echo $this->getBlockHtml('formkey'); ?>
  • i've done it but I don't see any change. After </form> do you mean? – Jon Zangitu Dec 10 '15 at 12:33
  • You all were right. The web is using jm_flannel theme, and it was the unique register.phtml that the patch didn't update. – Jon Zangitu Dec 10 '15 at 12:43
  • @Qaisar where it will add <?php echo $this->getBlockHtml('formkey'); ?> – Nadh May 25 '17 at 13:18
  • @Nadh in your form area. – Qaisar Satti May 25 '17 at 15:00
  • <form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate"> <?php echo $this->getBlockHtml('formkey'); ?> like this? – Nadh May 25 '17 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.