4

Currently, change password form is on the same page as account edit information, is there any way to separate change password to different page.

I'm new to Magento & don't know, how to create a custom page can be made in Magento.

4

I might be late in answering but this will surely help at least others. Magento has an existing separate file for change password. We are going to use that. The file path is:

app/design/frontend/base/default/template/customer/form/changepassword.phtml

It is not defined in any of the layout files so firstly we will have to mention it in a layout file. I mentioned it in local.xml Since I wanted to use it in customer/account/edit page only but the change password form to be separate from the edit account form I mentioned it under customer_account_edit. You can change the layout handle according to your preference.

In your theme's local.xml file add:

<customer_account_edit>
 <reference name="my.account.wrapper">
  <block type="customer/form_edit" name="customer_edit" template="customer/form/edit.phtml">
          <block type="core/template" name="change_password" template="customer/form/changepassword.phtml"/>
  </block>
  </reference>
</customer_account_edit>

In your customer/form/edit.phtml just add this line after the form tag closes:

<?php echo $this->getChildHtml('change_password'); ?>

In your changepassword.phtml file add the form key inside your <form> by adding this line:

<?php echo $this->getBlockHtml('formkey') ?>

Also, add a hidden field in changepassword.phtml file:

<input type="hidden" name="change_password" id="change_password" value="1" />

And you are good to go!

0

First check how to create custom page.Please study here

=> Step1: First of all create module control file Module name as Amit_Custommodule.xml at app/etc/modules/

Code is:

<?xml version="1.0"?>
<config>
    <modules>
        <Amit_Custommodule>
            <codePool>community</codePool>
            <active>true</active>
        </Amit_Custommodule>
    </modules>
</config>

=> Step2: For create custom route then you need to create config.xml at app/code/community/Amit/Custommodule/etc/

<?xml version="1.0" ?>
<config>
    <modules>
        <Amit_Custommodule>
            <version>1.0.0</version>
        </Amit_Custommodule>
    </modules>
    <!-- start of routers 
    -->
    <frontend>
        <routers>
            <custommodule>
                <use>standard</use>
                <args>
                    <module>Amit_Custommodule</module>
                    <frontName>custommodule</frontName>
                </args>
            </custommodule>
        </routers>
        <layout>
            <updates>
                <custommodule>
                    <file>custommodule.xml</file>
                </custommodule>
            </updates>
        </layout>
    </frontend>
</config>

**=> Step 3: Create Controller file where you have show password change form and post action **

<?php
class Amit_Custommodule_IndexController extends Mage_Core_Controller_Front_Action{

    protected function _getSession()
    {
        return Mage::getSingleton('customer/session');
    }
     public function _getModel($path, $arguments = array())
    {
        return Mage::getModel($path, $arguments);
    }


    public function editPostAction()
    {

        if ($this->getRequest()->isPost()) {
            /** @var $customer Mage_Customer_Model_Customer */
            $customer = $this->_getSession()->getCustomer();

            /** @var $customerForm Mage_Customer_Model_Form */
            $customerForm = $this->_getModel('customer/form');
            $customerForm->setFormCode('customer_account_edit')
                ->setEntity($customer);

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

            $errors = array();
            $customerErrors = $customerForm->validateData($customerData);
            if ($customerErrors !== true) {
                $errors = array_merge($customerErrors, $errors);
            } else {
                $customerForm->compactData($customerData);
                $errors = array();

                // If password change was requested then add it to common validation scheme
                if ($this->getRequest()->getParam('change_password')) {
                    $currPass   = $this->getRequest()->getPost('current_password');
                    $newPass    = $this->getRequest()->getPost('password');
                    $confPass   = $this->getRequest()->getPost('confirmation');

                    $oldPass = $this->_getSession()->getCustomer()->getPasswordHash();
                    if ( $this->_getHelper('core/string')->strpos($oldPass, ':')) {
                        list($_salt, $salt) = explode(':', $oldPass);
                    } else {
                        $salt = false;
                    }

                    if ($customer->hashPassword($currPass, $salt) == $oldPass) {
                        if (strlen($newPass)) {
                            /**
                             * Set entered password and its confirmation - they
                             * will be validated later to match each other and be of right length
                             */
                            $customer->setPassword($newPass);
                            $customer->setConfirmation($confPass);
                        } else {
                            $errors[] = $this->__('New password field cannot be empty.');
                        }
                    } else {
                        $errors[] = $this->__('Invalid current password');
                    }
                }

                // Validate account and compose list of errors if any
                $customerErrors = $customer->validate();
                if (is_array($customerErrors)) {
                    $errors = array_merge($errors, $customerErrors);
                }
            }

            if (!empty($errors)) {
                $this->_getSession()->setCustomerFormData($this->getRequest()->getPost());
                foreach ($errors as $message) {
                    $this->_getSession()->addError($message);
                }
                $this->_redirect('custommodule');
                return $this;
            }

            try {
                $customer->setConfirmation(null);
                $customer->save();
                $this->_getSession()->setCustomer($customer)
                    ->addSuccess($this->__('The account information has been saved.'));

                $this->_redirect('custommodule');
                return;
            } catch (Mage_Core_Exception $e) {
                $this->_getSession()->setCustomerFormData($this->getRequest()->getPost())
                    ->addError($e->getMessage());
            } catch (Exception $e) {
                $this->_getSession()->setCustomerFormData($this->getRequest()->getPost())
                    ->addException($e, $this->__('Cannot save the customer.'));
            }
        }

        $this->_redirect('custommodule');
    }
}
  • Thank You for the helo Amit, how to access this via URL? – Shabbir Lakdawala Mar 23 '15 at 5:19
  • Hi! And how to define custommodule.xml to show the password change form? – Shaine Eugene Mednikov Feb 26 '17 at 1:42
  • I've tried it like this as well: class Web3d_ChangePassword_IndexController extends Mage_Core_Controller_Front_Action{ public function indexAction() { $this->loadLayout(); $this->_initLayoutMessages('customer/session'); $this->_initLayoutMessages('catalog/session'); $this->getLayout()->getBlock('content')->append( $this->getLayout()->createBlock('customer/account_dashboard') ); $this->getLayout()->getBlock('head')->setTitle($this->__('My Account')); $this->renderLayout(); } – Shaine Eugene Mednikov Feb 26 '17 at 1:42

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.