2

I like to override magento/module-customer/view/frontend/templates/form/edit.phtml template, in my desktop it works but in our development server, I got this page

enter image description here

looks like there's inheritance not working PS: We have a custom theme installed, luma theme with some modifications

so I created a module

In Vendor/ModuleName/view/frontend/layout/customer_account_edit.xml

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
<body>
    <referenceBlock name="head.components">
        <block class="Magento\Framework\View\Element\Js\Components" name="customer_account_edit_head_components" template="Magento_Customer::js/components.phtml"/>
    </referenceBlock>
    <referenceBlock name="page.main.title">
        <action method="setPageTitle">
            <argument translate="true" name="title" xsi:type="string">Edit Account Information</argument>
        </action>
    </referenceBlock>
    <referenceContainer name="content">
        <block class="Magento\Customer\Block\Form\Edit" name="customer_edit" template="Vendor_ModuleName::form/edit.phtml" cacheable="false">
            <container name="form.additional.info" as="form_additional_info"/>
        </block>
    </referenceContainer>
</body>
</page>

And in Vendor/ModuleName/view/frontend/templates/form/edit.phtml

<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/** @var \Magento\Customer\Block\Form\Edit $block */
?>
<form class="form form-edit-account" action="<?= $block->escapeUrl($block->getUrl('customer/account/editPost')) ?>" method="post" id="form-validate" enctype="multipart/form-data" data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>" autocomplete="off">
<fieldset class="fieldset info">
    <?= $block->getBlockHtml('formkey') ?>
    <legend class="legend"><span><?= $block->escapeHtml(__('Account Information')) ?></span></legend><br>
    <?= $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')->setObject($block->getCustomer())->toHtml() ?>
    
    <?php $_dob = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?>
    <?php $_taxvat = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Taxvat') ?>
    <?php $_gender = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Gender') ?>
    <?php if ($_dob->isEnabled()): ?>
        <?= $_dob->setDate($block->getCustomer()->getDob())->toHtml() ?>
    <?php endif ?>
    <?php if ($_taxvat->isEnabled()): ?>
        <?= $_taxvat->setTaxvat($block->getCustomer()->getTaxvat())->toHtml() ?>
    <?php endif ?>
    <?php if ($_gender->isEnabled()): ?>
        <?= $_gender->setGender($block->getCustomer()->getGender())->toHtml() ?>
    <?php endif ?>
    
    <div class="field choice">
        <input type="checkbox" name="change_email" id="change-email" data-role="change-email" value="1" title="<?= $block->escapeHtmlAttr(__('Change Email')) ?>" class="checkbox" />
        <label class="label" for="change-email"><span><?= $block->escapeHtml(__('Change Email')) ?></span></label>
    </div>
    <div class="field choice">
        <input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" title="<?= $block->escapeHtmlAttr(__('Change Password')) ?>"<?php if ($block->getChangePassword()): ?> checked="checked"<?php endif; ?> class="checkbox" />
        <label class="label" for="change-password"><span><?= $block->escapeHtml(__('Change Password')) ?></span></label>
    </div>
    <div class="field field-name-invoice_email">
        <label class="label" for="invoice_email"><span>Invoice Email</span></label>
        <div class="control">
            <input type="text" id="invoice_email" name="invoice_email" value="<?php echo $block->getCustomer()->getCustomAttribute('invoice_email')->getValue(); //echo $this->htmlEscape($this->getFormData()->getInvoice_Email()) ?>" title="Last Name" class="input-text required-entry" data-validate="{required:true}" aria-required="true">
        </div>
    </div>
</fieldset>

<fieldset class="fieldset password" data-container="change-email-password">
    <legend class="legend"><span data-title="change-email-password"><?= $block->escapeHtml(__('Change Email and Password')) ?></span></legend><br>
    <div class="field email required" data-container="change-email">
        <label class="label" for="email"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
        <div class="control">
            <input type="email" name="email" id="email" autocomplete="email" data-input="change-email" value="<?= $block->escapeHtmlAttr($block->getCustomer()->getEmail()) ?>" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" class="input-text" data-validate="{required:true, 'validate-email':true}" />
        </div>
    </div>
    <div class="field password current required">
        <label class="label" for="current-password"><span><?= $block->escapeHtml(__('Current Password')) ?></span></label>
        <div class="control">
            <input type="password" class="input-text" name="current_password" id="current-password" data-input="current-password" autocomplete="off" />
        </div>
    </div>
    <div class="field new password required" data-container="new-password">
        <label class="label" for="password"><span><?= $block->escapeHtml(__('New Password')) ?></span></label>
        <div class="control">
            <input type="password" class="input-text" name="password" id="password"
                data-password-min-length="<?= $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
                data-password-min-character-sets="<?= $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
                data-input="new-password"
                data-validate="{required:true, 'validate-customer-password':true}"
                autocomplete="off" />
            <div id="password-strength-meter-container" data-role="password-strength-meter" aria-live="polite">
                <div id="password-strength-meter" class="password-strength-meter">
                    <?= $block->escapeHtml(__('Password Strength')) ?>:
                    <span id="password-strength-meter-label" data-role="password-strength-meter-label">
                        <?= $block->escapeHtml(__('No Password')) ?>
                    </span>
                </div>
            </div>
        </div>
    </div>
    <div class="field confirm password required" data-container="confirm-password">
        <label class="label" for="password-confirmation"><span><?= $block->escapeHtml(__('Confirm New Password')) ?></span></label>
        <div class="control">
            <input type="password" class="input-text" name="password_confirmation" id="password-confirmation"
                data-input="confirm-password"
                autocomplete="off" />
        </div>
    </div>
</fieldset>

<?= $block->getChildHtml('form_additional_info') ?>
<div class="actions-toolbar">
    <div class="primary">
        <button type="submit" class="action save primary" title="<?= $block->escapeHtmlAttr(__('Save')) ?>"><span><?= $block->escapeHtml(__('Save')) ?></span></button>
    </div>
    <div class="secondary">
        <a class="action back" href="<?= $block->escapeUrl($block->getBackUrl()) ?>"><span><?= $block->escapeHtml(__('Go back')) ?></span></a>
    </div>
</div>
</form>
<script>
require([
    "jquery",
    "mage/mage"
], function($){
    var dataForm = $('#form-validate');
    var ignore = <?= /* @noEscape */ $_dob->isEnabled() ? '\'input[id$="full"]\'' : 'null' ?>;
    
    dataForm.mage('validation', {
    <?php if ($_dob->isEnabled()): ?>
        errorPlacement: function(error, element) {
            if (element.prop('id').search('full') !== -1) {
                var dobElement = $(element).parents('.customer-dob'),
                    errorClass = error.prop('class');
                error.insertAfter(element.parent());
                dobElement.find('.validate-custom').addClass(errorClass)
                    .after('<div class="' + errorClass + '"></div>');
            }
            else {
                error.insertAfter(element);
            }
        },
        ignore: ':hidden:not(' + ignore + ')'
    <?php else: ?>
        ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
    <?php endif ?>
    });

});
</script>
<script type="text/x-magento-init">
{
    "[data-role=change-email], [data-role=change-password]": {
        "changeEmailPassword": {
            "titleChangeEmail": "<?= $block->escapeJs($block->escapeHtml(__('Change Email'))) ?>",
            "titleChangePassword": "<?= $block->escapeJs($block->escapeHtml(__('Change Password'))) ?>",
            "titleChangeEmailAndPassword": "<?= $block->escapeJs($block->escapeHtml(__('Change Email and Password'))) ?>"
        }
    },
    "[data-container=new-password]": {
        "passwordStrengthIndicator": {
            "formSelector": "form.form-edit-account"
        }
    }
}
</script>

In etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Wetag_InvoiceEmail" setup_version="1.0.0">
    <sequence>
        <module name="Magento_Backend"/>
         <module name="Magento_Sales"/>
        <module name="Magento_Quote"/>
        <module name="Magento_Checkout"/>
        <module name="Magento_Cms"/>
        <module name="Magento_Customer"/>
    </sequence>
</module>
</config>

3 Answers 3

0

Suppose your module: SR_MagentoCommunity. Try following way:

app/code/SR/MagentoCommunity/view/frontend/layout/customer_account_edit.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_edit" template="SR_MagentoCommunity::form/edit.phtml"/>
    </body>
</page>

After that copy original phtml under your module, location:

app/code/SR/MagentoCommunity/view/frontend/templates/form/edit.phtml

2
  • This is what i made, this works on my local installation but in server we have a custom theme and override is not working, it shows the edit.phtml content only Commented Apr 26, 2019 at 14:14
  • 1
    I found the error i was using a custm attribute <?php echo $block->getCustomer()->getCustomAttribute('invoice_email')->getValue(); //echo $this->htmlEscape($this->getFormData()->getInvoice_Email()) ?> in my new text field value and it's not set Commented Apr 26, 2019 at 14:17
0

If you have enabled html minification there is a good chance that the version the frontend is using is not your local override but a version created from the override which is minified and stored elsewhere. If in doubt turn on template hints.

1
  • The problem was with a php error <input type="text" id="invoice_email" name="invoice_email" value="<?php echo $block->getCustomer()->getCustomAttribute('invoice_email')->getValue(); //echo $this->htmlEscape($this->getFormData()->getInvoice_Email()) ?>" title="Last Name" class="input-text required-entry" data-validate="{required:true}" aria-required="true"> $block->getCustomer()->getCustomAttribute('invoice_email') return null Commented Apr 29, 2019 at 15:39
0

If you have created a module then you also need to overwrite the xml file: contact_index_index.xml

overwrite the contactForm block like:

<referenceBlock name="contactForm" template="Vendor_ModuleName::form/edit.phtml"/>

After this use your custom form file. It will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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