0

I have added a forgot password form to all the pages, by adding the following line in the default.xml of my custom theme:

<block class="Magento\Customer\Block\Account\Forgotpassword" name="forgotPassword.pop" template="Magento_Customer::form/forgotpassword.phtml">

But, when the end-user clicks on the Reset my password button, the page redirects to this URL:

/cms/index/forgotpasswordpost

And the page returns the 404 (screenshot is attached).

Any help is greatly appreciated.

M 2.2

nested-forgotpassword-form-404-error

0
  1. If you want to just add a forgetpassword link:

    Add the code bellow in your default.xml

    <container name="forgetpassword-custom" label="forgetpassword link in all pages" htmlTag="div" htmlClass="forgetpassword-custom-link">
        <block class="Magento\Framework\View\Element\Html\Link" name="forgetpassword.custom">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Forgot Your Password ?</argument>
                <argument name="path" xsi:type="string" translate="true">customer/account/forgotpassword/</argument>
                <argument name="sortOrder" xsi:type="number">100</argument>
            </arguments>
        </block>
    </container>
    
  2. If you want to add completely the forgetpassword form then you submit it correctly without your 404 error

    app/design/frontend/Vendor/theme-name/Magento_Theme/templates/html/forgetpassword-custom.phtml

    <form class="form password forget"
      action="<?= $block->escapeUrl($block->getUrl('customer/account/forgotpasswordpost')) ?>"
      method="post"
      id="form-validate"
      data-mage-init='{"validation":{}}'>
    <fieldset class="fieldset" data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>">
        <div class="field note"><?= $block->escapeHtml(__('Please enter your email address below to receive a password reset link.')) ?></div>
        <div class="field email required">
            <label for="email_address" class="label"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
            <div class="control">
                <input type="email" name="email" alt="email" id="email_address" class="input-text" value="<?= $block->escapeHtmlAttr($block->getEmailValue()) ?>" data-validate="{required:true, 'validate-email':true}">
            </div>
        </div>
        <?= $block->getChildHtml('form_additional_info') ?>
    </fieldset>
    <div class="actions-toolbar">
        <div class="primary">
            <button type="submit" class="action submit primary"><span><?= $block->escapeHtml(__('Reset My Password')) ?></span></button>
        </div>
        <div class="secondary">
            <a class="action back" href="<?= $block->escapeUrl($block->getLoginUrl()) ?>"><span><?= $block->escapeHtml(__('Go back')) ?></span></a>
        </div>
    </div>
    </form>
    

    app/design/frontend/Vendor/theme-name/Magento_Theme/layout/default.xml

    <block class="Magento\Framework\View\Element\Template" name="forgetpassword.custom" template="Magento_Theme::html/forgetpassword-custom.phtml" />
    

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.