2016-02-19 101 views
2

magento 1.9X註冊不工作在magento

我正在使用下面的參考創建ajax登錄/註冊彈出。 登錄工作正常。但無法註冊。

http://fastdivision.com/2012/03/29/diy-magento-create-ajax-login-registration-forms-for-your-magento-theme/
它給出了同樣的錯誤彈出「請確保您的密碼匹配」。即使我使用現有的email.same彈出錯誤出現。

<div id="login-modal" class="modal-window"> 
    <div id="login-modal-content"> 
    <div id="signup-box"> 
    <h1>Register</h1> 
    <p><a href="#" id="already-registered-link">Already registered? Click here to sign in.</a></p> 

    <form action="<?php echo Mage::getBaseUrl() ?>customer/account/createpost/" method="post" id="signup-form" class="site-form" onsubmit="return false"> 
    <ul class="form-list"> 
     <li class="fields"> 
      <div class="field first-field"> 
       <label for="firstname" class="required"><?php echo $this->__('First Name') ?><em>*</em></label> 
       <div class="input-box"> 
        <input type="text" name="firstname" id="firstname" class="input-text validate-email required-entry" /> 
       </div> 
      </div> 
      <div class="field"> 
       <label for="last_name" class="required"><?php echo $this->__('Last Name') ?><em>*</em></label> 
       <div class="input-box"> 
        <input type="text" name="lastname" id="lastname" class="input-text validate-email required-entry" /> 
       </div> 
      </div> 
      <div class="field"> 
       <label for="email_address" class="required"><?php echo $this->__('Email') ?><em>*</em></label> 
       <div class="input-box"> 
        <input type="text" name="email" id="email_address" class="input-text validate-email required-entry" /> 
       </div> 
      </div> 
      <div class="field"> 
       <label for="password" class="required"><?php echo $this->__('Password') ?><em>*</em></label> 
       <div class="input-box"> 
        <input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" /> 
       </div> 
      </div> 
      <div class="field"> 
       <label for="confirmation" class="required"><?php echo $this->__('Confirm Password') ?><em>*</em></label> 
       <div class="input-box"> 
        <input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" /> 
       </div> 
      </div> 
     </li> 
    </ul> 

    <button type="submit" title="Submit" class="action-button"><span>Create Account</span></button> 
    </form> 
</div> 
<div id="login-box"> 
    <h1>Login</h1> 
    <p><?php echo $this->__('If you have an account with us, please log in.') ?></p> 
    <p><a href="#" id="need-account-link">Need an account? Click here to register.</a></p> 

    <form action="<?php echo Mage::getBaseUrl() ?>customer/account/loginPost/" method="post" id="login-form" class="site-form" onsubmit="return false"> 
    <ul class="form-list"> 
     <li class="field"> 
      <label for="email" class="required"><?php echo $this->__('Email') ?><em>*</em></label> 
      <div class="input-box"> 
       <input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text" title="<?php echo $this->__('Email Address') ?>" /> 
      </div> 
     </li> 
     <li class="field"> 
      <label for="pass" class="required"><?php echo $this->__('Password') ?><em>*</em></label> 
      <div class="input-box"> 
       <input type="password" name="login[password]" class="input-text" id="pass" title="<?php echo $this->__('Password') ?>" /> 
      </div> 
     </li> 
    </ul> 

     <button type="submit" class="action-button action-button-no-arrow" title="<?php echo $this->__('Login') ?>" name="send" id="send2"><span><?php echo $this->__('Login') ?></span></button>&nbsp;&nbsp; 
     <a href="<?php echo $this->getForgotPasswordUrl() ?>" class="small"><?php echo $this->__('Forgot Your Password?') ?></a> 
     </form> 
    </div> 
    </div> 
    <a id="close_x" class="close" href="#"><i class="fa fa-close"></i></a> 
    <script type="text/javascript"> 
    //<![CDATA[ 
    var dataForm = new VarienForm('login-form', true); 
    //]]> 
    </script> 
</div> 
+0

您可以提供的網址,讓你已經試過這個 –

+0

,你沒有發佈你的phtml –

+0

我試過l ocalhost。 – nilesh

回答

0
在Magento 1.9

每當顧客結賬或寄存器的店面,「請確認您的密碼匹配「彈出即使您的密碼和確認密碼字段相同。在Magento 1.9版中,要驗證確認類「Mage_Customer_Model_Customer」中的密碼值方法validate()已更改了一下。

前:

$confirmation = $this->getConfirmation(); 

後:

$confirmation = $this->getPasswordConfirmation(); 

所以,如果你得到了同樣的問題,而結算和登記,行更改爲

$confirmation = $this->getConfirmation(); 
1

,我可以從你收到的錯誤看,該問題是由觸發

config.xml中

<?xml version="1.0"?> 
<config> 
<modules> 
    <FastDivision_QuickLogin> 
     <version>1.0.0</version> 
    </FastDivision_QuickLogin> 
</modules> 
<frontend> 
    <routers> 
     <customer> 
      <args> 
       <modules> 
        <FastDivision_QuickLogin before="Mage_Customer">FastDivision_QuickLogin_Customer</FastDivision_QuickLogin> 
        <!--<FastDivision_QuickLogin before="Mage_Customer_Account">FastDivision_QuickLogin_Customer</FastDivision_QuickLogin> 
        <FastDivision_QuickLogin before="Mage_Customer_AccountController">FastDivision_QuickLogin_Customer</FastDivision_QuickLogin>--> 
       </modules> 
      </args> 
     </customer> 
    </routers> 
</frontend> 
</config> 

AccountController.php

<?php 
// Require the core controller file that you're planning to override 
require_once('Mage/Customer/controllers/AccountController.php'); 

// The class name follows this format: 
// YOURPACKAGE_YOUREXTENSION_COREMODULEFOLDER_CONTROLLERFILENAME 
// We extend the original Mage_Customer_AccountController class to inherit unused actions and override specific actions 
class FastDivision_QuickLogin_Customer_AccountController extends Mage_Customer_AccountController 
{ 
// Code referenced from AccountController.php 
public function loginPostAction() 
{ 
    if(!$this->getRequest()->isXmlHttpRequest()) { 
     if ($this->_getSession()->isLoggedIn()) { 
      $this->_redirect('*/*/'); 
      return; 
     } 
    } 

    $session = $this->_getSession(); 

    if($this->getRequest()->isXmlHttpRequest()) { 
     // Report exceptions via JSON 
     $ajaxExceptions = array(); 
    } 

    if ($this->getRequest()->isPost()) { 
     $login = $this->getRequest()->getPost('login'); 
     if (!empty($login['username']) && !empty($login['password'])) { 
      try { 
       $session->login($login['username'], $login['password']); 
       if ($session->getCustomer()->getIsJustConfirmed()) { 
        $this->_welcomeCustomer($session->getCustomer(), true); 
       } 
      } catch (Mage_Core_Exception $e) { 
       if($this->getRequest()->isXmlHttpRequest()) { 
        $messages = array_unique(explode("\n", $e->getMessage())); 
        foreach ($messages as $message) { 
         $ajaxExceptions['exceptions'][] = $message; 
        } 
       } else { 
        switch ($e->getCode()) { 
         case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED: 
          $value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']); 
          $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value); 
          break; 
         case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD: 
          $message = $e->getMessage(); 
          break; 
         default: 
          $message = $e->getMessage(); 
        } 
        $session->addError($message); 
       } 

       $session->setUsername($login['username']); 
      } catch (Exception $e) { 
       // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password 
      } 
     } else { 
      if($this->getRequest()->isXmlHttpRequest()) { 
       $ajaxExceptions['exceptions'][] = 'Login and password are required.'; 
      } else { 
       $session->addError($this->__('Login and password are required.')); 
      } 
     } 
    } 

    if($this->getRequest()->isXmlHttpRequest()) { 
     // If errors 
     if(count($ajaxExceptions)) { 
      echo json_encode($ajaxExceptions); 
     } else { 
      // No Errors 
      echo json_encode(array('success' => 'success')); 
     } 
    } else { 
     // Redirect for non-ajax 
     $this->_loginPostRedirect(); 
    } 
} 

// Create Account 
public function createPostAction() 
{ 
    if($this->getRequest()->isXmlHttpRequest()) { 
     // Report exceptions via JSON 
     $ajaxExceptions = array(); 
    } 

    $session = $this->_getSession(); 
    if ($session->isLoggedIn()) { 
     $this->_redirect('*/*/'); 
     return; 
    } 
    $session->setEscapeMessages(true); // prevent XSS injection in user input 
    if ($this->getRequest()->isPost()) { 
     $errors = array(); 

     if (!$customer = Mage::registry('current_customer')) { 
      $customer = Mage::getModel('customer/customer')->setId(null); 
     } 

     /* @var $customerForm Mage_Customer_Model_Form */ 
     $customerForm = Mage::getModel('customer/form'); 
     $customerForm->setFormCode('customer_account_create') 
      ->setEntity($customer); 

     $customerData = $customerForm->extractData($this->getRequest()); 

     if ($this->getRequest()->getParam('is_subscribed', false)) { 
      $customer->setIsSubscribed(1); 
     } 

     /** 
     * Initialize customer group id 
     */ 
     $customer->getGroupId(); 

     if ($this->getRequest()->getPost('create_address')) { 
      /* @var $address Mage_Customer_Model_Address */ 
      $address = Mage::getModel('customer/address'); 
      /* @var $addressForm Mage_Customer_Model_Form */ 
      $addressForm = Mage::getModel('customer/form'); 
      $addressForm->setFormCode('customer_register_address') 
       ->setEntity($address); 

      $addressData = $addressForm->extractData($this->getRequest(), 'address', false); 
      $addressErrors = $addressForm->validateData($addressData); 
      if ($addressErrors === true) { 
       $address->setId(null) 
        ->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false)) 
        ->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false)); 
       $addressForm->compactData($addressData); 
       $customer->addAddress($address); 

       $addressErrors = $address->validate(); 
       if (is_array($addressErrors)) { 
        $errors = array_merge($errors, $addressErrors); 
       } 
      } else { 
       $errors = array_merge($errors, $addressErrors); 
      } 
     } 

     try { 
      $customerErrors = $customerForm->validateData($customerData); 
      if ($customerErrors !== true) { 
       $errors = array_merge($customerErrors, $errors); 
      } else { 
       $customerForm->compactData($customerData); 
       $customer->setPassword($this->getRequest()->getPost('password')); 
       $customer->setConfirmation($this->getRequest()->getPost('confirmation')); 
       $customerErrors = $customer->validate(); 
       if (is_array($customerErrors)) { 
        $errors = array_merge($customerErrors, $errors); 
       } 
      } 

      $validationResult = count($errors) == 0; 

      if (true === $validationResult) { 
       $customer->save(); 

       Mage::dispatchEvent('customer_register_success', 
        array('account_controller' => $this, 'customer' => $customer) 
       ); 

       if ($customer->isConfirmationRequired()) { 
        $customer->sendNewAccountEmail(
         'confirmation', 
         $session->getBeforeAuthUrl(), 
         Mage::app()->getStore()->getId() 
        ); 
        $session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail()))); 

        if($this->getRequest()->isXmlHttpRequest()) { 
         echo json_encode(array('success' => $this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())))); 
        } else { 
         $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true))); 
        } 

        return; 
       } else { 
        $session->setCustomerAsLoggedIn($customer); 
        $url = $this->_welcomeCustomer($customer); 

        if($this->getRequest()->isXmlHttpRequest()) { 
         echo json_encode(array('success' => 'success')); 
        } else { 
         $this->_redirectSuccess($url); 
        } 

        return; 
       } 
      } else { 
       $session->setCustomerFormData($this->getRequest()->getPost()); 

       if(!$this->getRequest()->isXmlHttpRequest()) { 
        if (is_array($errors)) { 
         foreach ($errors as $errorMessage) { 
          $session->addError($errorMessage); 
         } 
        } else { 
         $session->addError($this->__('Invalid customer data')); 
        } 
       } else { 
        if (is_array($errors)) { 
         foreach ($errors as $errorMessage) { 
          $ajaxExceptions['exceptions'][] = $errorMessage; 
         } 
        } else { 
         $ajaxExceptions['exceptions'][] = 'Invalid customer data'; 
        } 
       } 
      } 
     } catch (Mage_Core_Exception $e) { 
      $session->setCustomerFormData($this->getRequest()->getPost()); 
      if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) { 
       $url = Mage::getUrl('customer/account/forgotpassword'); 
       $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url); 
       $session->setEscapeMessages(false); 
      } else { 
       $message = $e->getMessage(); 
      } 

      if(!$this->getRequest()->isXmlHttpRequest()) { 
       $session->addError($message); 
      } else { 
       $messages = array_unique(explode("\n", $e->getMessage())); 
       foreach ($messages as $message) { 
        $ajaxExceptions['exceptions'][] = $message; 
       } 
      } 
     } catch (Exception $e) { 
      if(!$this->getRequest()->isXmlHttpRequest()) { 
       $session->setCustomerFormData($this->getRequest()->getPost()) 
       ->addException($e, $this->__('Cannot save the customer.')); 
      } else { 
       $ajaxExceptions['exceptions'][] = 'Cannot save the customer.'; 
      } 
     } 
    } 

    if($this->getRequest()->isXmlHttpRequest()) { 
     echo json_encode($ajaxExceptions); 
    } else { 
     $this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true))); 
    } 
} 
} 

quick_login.phtml缺少「密碼確認」表單。

即使您決定隱藏它,也必須使用它才能在控制器中複製密碼,直到用戶在保存前進行驗證。在createPostAction方法的出口

檢查數據:

var_dump($this->getRequest()->getPost()); 

或通過調試(如果你正在使用它)。

陣列應具有以下觀點: https://gyazo.com/52d5c7fe80316b9f8f3773fcfa1f6462

這是所需要的參數(那些填寫)的最小值。

如果數組中沒有包含帶確認鍵的元素和與密碼對應的含義,則它將被忽略並跳過模板(.phtml)的某處。

如果它仍然存在,你應該在createPostAction中檢查整個實現的操作集合,並在調用Mage_Customer_Model_Customer :: validate()(它是生成錯誤的位置)之前找到它的位置, 。

如果你不使用AJAX和使用提交選項發送的形式,你應該刪除這個表格屬性

onsubmit="return false;" 
+0

感謝您的reply.it幫助我。我發現下面的文章幫助了我。 – nilesh

+0

我改變了$ confirmation = $ this-> getPasswordConfirmation(); TO $確認= $ this-> getConfirmation();在Mage_Customer_Model_Customer裏面的validate方法。 – nilesh

+0

將來會導致任何問題。我是magento的新手。 – nilesh