2

I'm trying to overwrite contact form but it's unable to overriding. For this I have followed below steps.

Step 1) app/code/Learning/Contact/composer.json

{
  "name": "learning/contact",
  "description": "contact",
  "require": {
      "php": "~5.5.0|~5.6.0|~7.0.0",
      "magento/framework": "100.0.*",
      "magento/module-ui": "100.0.*",
      "magento/module-config": "100.0.*"
  },
  "type": "magento2-module",
  "version": "1.0.0",
  "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
  "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "Learning\\Contact\\": ""
        }
    }
}

Step 2) app/code/Learning/Contact/registration.php

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

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Learning_Contact',
    __DIR__
);

Step 3) app/code/Learning/Contact/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="Learning_Contact" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Contact"/>
        </sequence>
    </module>
</config>

Step 4) app/code/Learning/Contact/view/frontend/layout/contact_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Contact Us</title>
    </head>
    <body>
        <referenceContainer name="content">
            <referenceBlock name="contactForm">
                <action method="setTemplate">
                    <argument name="template" translate="true" xsi:type="string">Learning_Contact::form.phtml</argument>
                </action>
            </referenceBlock>
        </referenceContainer>
    </body>
</page>

Step 5) app/code/Learning/Contact/view/frontend/templates/form.phtml

<h1> Hi I'm here.... </h1>

Step 6) cleared cache

php bin/magento cache:clean

Step 7) enabled module

php bin/magento setup:upgrade

Is above steps are correct or something went wrong?

Could you please throw me right direction?

3

Your app/code/Learning/Contact/view/frontend/layout/contact_index_index.xml is wrong configured

Change this files to

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Contact Us</title>
    </head>
    <body>
        <referenceBlock name="contactForm">
                <action method="setTemplate">
                    <argument name="template" translate="true" xsi:type="string">Learning_Contact::form.phtml</argument>
                </action>
         </referenceBlock>
    </body>
</page>

Just remove <referenceContainer name="content"> and </referenceContainer> from your contact_index_index.xml

Don't forgot to clear cache

  • It's not mandatory to remove <referenceContainer name="content"> and </referenceContainer> even I keep this I'm getting result. the problem with cookie with chrome brower. It's working IE. – Bojjaiah Nov 20 '15 at 6:54
1

In composer.json name should be

learning/module-contact

So, Change your composer.json following code

{
    "name": "learning/module-contact",
    "description": "contact",
    "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "magento/framework": "100.0.*",
        "magento/module-ui": "100.0.*",
        "magento/module-config": "100.0.*",
        "magento/module-contact": "100.0.*"
    },
    "type": "magento2-module",
    "version": "100.0.0",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [ "registration.php" ],
        "psr-4": {
            "Learning\\Contact\\": ""
        }
    }
}

clear cache and run upgrade command again.

php bin/magento setup:upgrade
  • learning/module-contact it's standard or mandatory? even my composer also working fine without modifying. however cookie problem in chrome browser. – Bojjaiah Nov 20 '15 at 6:58
  • This name field should be fully-qualified module name in the format <vendor-name>/module-<module-name>. It's mandatory. – Sohel Rana Nov 20 '15 at 7:23
  • For more information devdocs.magento.com/guides/v2.0/extension-dev-guide/… – Sohel Rana Nov 20 '15 at 7:24
0

You can also set code in contact_index_index display below:

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Contact Us</title>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Krish_Contact::form.phtml">
                <container name="form.additional.info" label="Form Additional Info"/>
            </block>
        </referenceContainer>
    </body>
</page>

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.