cancel
Showing results for 
Search instead for 
Did you mean: 

2.3.5-P1 to 2.4.0 Contact Form Error

Highlighted

2.3.5-P1 to 2.4.0 Contact Form Error

I've upgraded via composer from 2.3.5-P1 to 2.4.0

 

Everything went smoothly apart from the contact form. Using a child theme based on Luma. If i call the contact form on the Contact Page, using:

{{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}

The page completely breaks - no theme visible, just the first line of a broken contact form.

 

Exception log shows the following error:

main.CRITICAL: Invalid block type: MagentoContactBlockContactForm {"exception":"[object] (Magento\\Framework\\Exception\\LocalizedException(code: 0): Invalid block type: MagentoContactBlock$

When enabling developer mode, and viewing page source, I see this error:

3 id="contact-form"
4 method="post"
5 data-hasrequired="* Required Fields"
6 data-mage-init='{"validation":{}}'>
7 <fieldset class="fieldset">
8 <legend class="legend"><span>Write Us</span></legend><br />
9 <div class="field note no-label">
10 Jot us a note and we’ll get back to you as quickly as possible. </div>
11 <div class="field name required">
12 <label class="label" for="name"><span>Name</span></label>
13 <div class="control">
14 <input name="name"
15 id="name"
16 title="Name"
17 value="Error: Call to a member function getUserName() on null in
/var/www/eme/vendor/magento/module-contact/view/frontend/templates/form.phtml:29

Any thought on what the issue could be?

7 REPLIES 7
Highlighted

Re: 2.3.5-P1 to 2.4.0 Contact Form Error

Hello @emeservices ,

Have your overwritten vendor/magento/module-contact/view/frontend/templates/form.phtml in your theme?

If yes, then please share the code so that I can get better understanding of the problem.

Thanks

Highlighted

Re: 2.3.5-P1 to 2.4.0 Contact Form Error

No, I haven't overwritten any core files

 

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

/** @var \Magento\Contact\Block\ContactForm $block */
/** @var \Magento\Contact\ViewModel\UserDataProvider $viewModel */

$viewModel = $block->getViewModel();
?>
<form class="form contact"
      action="<?= $block->escapeUrl($block->getFormAction()) ?>"
      id="contact-form"
      method="post"
      data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>"
      data-mage-init='{"validation":{}}'>
    <fieldset class="fieldset">
        <legend class="legend"><span><?= $block->escapeHtml(__('Write Us')) ?></span></legend><br />
        <div class="field note no-label">
            <?= $block->escapeHtml(__('Jot us a note and we’ll get back to you as quickly as possible.')) ?>
        </div>
        <div class="field name required">
            <label class="label" for="name"><span><?= $block->escapeHtml(__('Name')) ?></span></label>
            <div class="control">
                <input name="name"
                       id="name"
                       title="<?= $block->escapeHtmlAttr(__('Name')) ?>"
                       value="<?= $block->escapeHtmlAttr($viewModel->getUserName()) ?>"
                       class="input-text"
                       type="text"
                       data-validate="{required:true}"/>
            </div>
        </div>
        <div class="field email required">
            <label class="label" for="email"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
            <div class="control">
                <input name="email"
                       id="email"
                       title="<?= $block->escapeHtmlAttr(__('Email')) ?>"
                       value="<?= $block->escapeHtmlAttr($viewModel->getUserEmail()) ?>"
                       class="input-text"
                       type="email"
                       data-validate="{required:true, 'validate-email':true}"/>
            </div>
        </div>
        <div class="field telephone">
            <label class="label" for="telephone"><span><?= $block->escapeHtml(__('Phone Number')) ?></span></label>
            <div class="control">
                <input name="telephone"
                       id="telephone"
                       title="<?= $block->escapeHtmlAttr(__('Phone Number')) ?>"
                       value="<?= $block->escapeHtmlAttr($viewModel->getUserTelephone()) ?>"
                       class="input-text"
                       type="tel" />
            </div>
        </div>
        <div class="field comment required">
            <label class="label" for="comment">
                <span><?= $block->escapeHtml(__('What’s on your mind?')) ?></span>
            </label>
            <div class="control">
                <textarea name="comment"
                     id="comment"
                     title="<?= $block->escapeHtmlAttr(__('What’s on your mind?')) ?>"
                     class="input-text"
                     cols="5"
                     rows="3"
                     data-validate="{required:true}"><?= $block->escapeHtml($viewModel->getUserComment()) ?></textarea>
            </div>
        </div>
        <?= $block->getChildHtml('form.additional.info') ?>
    </fieldset>
    <div class="actions-toolbar">
        <div class="primary">
            <input type="hidden" name="hideit" id="hideit" value="" />
            <button type="submit" title="<?= $block->escapeHtmlAttr(__('Submit')) ?>" class="action submit primary">
                <span><?= $block->escapeHtml(__('Submit')) ?></span>
            </button>
        </div>
    </div>
</form>
Highlighted

Re: 2.3.5-P1 to 2.4.0 Contact Form Error

Hi @emeservices 

 

Have you overridden view-model class ? what is the code of controller which is going to that particular page ?

 

it is not able to find view-model class/file.

Problem Solved ? Click on 'Kudos' & Accept as Solution to encourage to write more answers !
Highlighted

Re: 2.3.5-P1 to 2.4.0 Contact Form Error

Hi, it a very basic child theme of Luma, there are very few overrides. Everything was fully functional before the composer update to 2.4.0

 

I have the composer.json, registation.php and theme.xml in the theme root dir. /etc /media and /web are all empty

 

The only overrides I've made are:

/Magento_Theme/layout/default.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="header.panel">
            <block class="Magento\Framework\View\Element\Html\Links" name="header.links">
                <arguments>
                    <argument name="css_class" xsi:type="string">header links</argument>
                </arguments>
            </block>
        </referenceContainer>
        <referenceBlock name="logo">
            <arguments>
                <argument name="logo_img_width" xsi:type="number">148</argument>
                <argument name="logo_img_height" xsi:type="number">43</argument>
            </arguments>
        </referenceBlock>
        <referenceContainer name="footer">
            <block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" after="footer_links" template="Magento_Store::switch/stores.phtml"/>
        </referenceContainer>
        <referenceBlock name="report.bugs" remove="true"/>
        <move element="copyright" destination="before.body.end"/>
        <referenceBlock name="footer_links" remove="true"/>
    </body>
</page>

 

/Magento_LayeredNavigation/templates/layer/view.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php
/**
 * Category layered navigation
 *
 * @var $block \Magento\LayeredNavigation\Block\Navigation
 */
?>

<?php if ($block->canShowBlock()) : ?>
    <div class="block filter" id="layered-filter-block" data-mage-init='
    {
        "collapsible":
        {
            "openedState": "active",
            "collapsible": true,
            "active": false,
            "collateral":
            {
                "openedState": "filter-active",
                "element": "body"
            }
        }
    }'>
        <?php $filtered = count($block->getLayer()->getState()->getFilters()) ?>
        <div class="block-title filter-title" data-count="<?= /* @noEscape */ $filtered ?>">
            <strong data-role="title"><?= $block->escapeHtml(__('Shop By')); ?></strong>
        </div>
        <div class="block-content filter-content">
            <?= $block->getChildHtml('state') ?>

            <?php if ($block->getLayer()->getState()->getFilters()) : ?>
                <div class="block-actions filter-actions">
                    <a href="<?= $block->escapeUrl($block->getClearUrl()) ?>" class="action clear filter-clear">
                        <span><?= $block->escapeHtml(__('Clear All')) ?></span>
                    </a>
                </div>
            <?php endif; ?>
            <?php $wrapOptions = false; ?>
            <?php foreach ($block->getFilters() as $filter) : ?>
                <?php if ($filter->getItemsCount()) : ?>
                    <?php if (!$wrapOptions) : ?>
                        <strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?= $block->escapeHtml(__('Shopping Options')) ?></strong>
                        <div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='
                        {
                            "accordion":
                            {
                                "openedState": "active",
                                "collapsible": true,
                                "active": [0,1,2,3,4,5,6],
                                "multipleCollapsible": false
                            }
                        }'>
                        <?php $wrapOptions = true;
                        endif; ?>
                    <div data-role="collapsible" class="filter-options-item">
                        <div data-role="title" class="filter-options-title"><?= $block->escapeHtml(__($filter->getName())) ?></div>
                        <div data-role="content" class="filter-options-content"><?= /* @noEscape */ $block->getChildBlock('renderer')->render($filter) ?></div>
                    </div>
                <?php endif; ?>
            <?php endforeach; ?>
            <?php if ($wrapOptions) : ?>
                </div>
            <?php else : ?>
                <script>
                    require([
                        'jquery'
                    ], function ($) {
                        $('#layered-filter-block').addClass('filter-no-options');
                    });
                </script>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>

/Magento_Customer/layout/default.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="header.links">
            <block class="Magento\Customer\Block\Account\Customer" name="customer" template="Magento_Customer::account/customer.phtml" before="-"/>
            <block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link-login" template="Magento_Customer::account/link/authorization.phtml">
            </block>
        </referenceBlock>

        <move element="top.links" destination="customer"/>
    </body>
</page>

Magento_Catalog/layout/default.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="catalog.compare.sidebar" remove="true"/>
        <referenceBlock name="category.product.addto.compare" remove="true"/>
        <referenceBlock name="catalogsearch.product.addto.compare" remove="true"/>
        <referenceBlock name="view.addto.compare" remove="true" />
        <referenceBlock name="crosssell.product.addto.compare" remove="true" />
        <referenceBlock name="related.product.addto.compare" remove="true" />
        <referenceBlock name="upsell.product.addto.compare" remove="true" />
    </body>
</page>

I've tried removing all these one by one just to test, but no to avail. There are no other modifications to any core files. 

Highlighted

Re: 2.3.5-P1 to 2.4.0 Contact Form Error

I am having this exact same problem.  Upon upgrading to 2.4.0 (from 2.3.5-p1), the default Contact Us form is broken.

 

I am using the default Magento Blank theme, with NO customized code.

 

It looks like this:

image.png

Based on that context, looking at the code in:

vendor/magento/module-contact/view/frontend/templates/form.phtml

It must be a problem with this call to $viewModel->getUserName:

            <div class="control">
                <input name="name" 
                       id="name" 
                       title="<?= $block->escapeHtmlAttr(__('Name')) ?>" 
                       value="<?= $block->escapeHtmlAttr($viewModel->getUserName
()) ?>" 
                       class="input-text" 
                       type="text" 
                       data-validate="{required:true}"/>
            </div>
        </div>

But I know nothing about the Magento code, classes, etc, so I have no idea what is wrong with the call.

 

I also want to add that I do have a "Contact Us" CONTENT->Pages page, which has:

<div style="float: left; padding-right: 15px;">
<p>Need some help? We'd love to hear from you!</p>
<p>Call us: 503-555-1212</p>
<p><img src="{{media url="woman-typing.jpg"}}" alt="" width="297" height="198">;</p>
</div>
<p>{{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}</p>

When I select "View" from the Action column, it breaks in the same way as when clicking on the "Contact Us" link from the frontend.

 

Thanks,

Evelyn

Highlighted

Re: 2.3.5-P1 to 2.4.0 Contact Form Error

Here's a little more data, hoping someone who knows the code will be able to fix it.  There was a traceback in the error that I just noticed.  It looks like this:

Error: Call to a member function getUserName() on null in
/var/www/html/magento/vendor/magento/module-contact/view/frontend/templates/form.phtml:29
Stack trace:#0 /var/www/html/magento/vendor/magento/framework/View/TemplateEngine/Php.php(71): include()
#1 /var/www/html/magento/vendor/magento/framework/View/Element/Template.php(273): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Contact\Block\ContactForm), '/var/www/html/m...', Array)
#2 /var/www/html/magento/vendor/magento/framework/View/Element/Template.php(303): Magento\Framework\View\Element\Template->fetchView('/var/www/html/m...')
#3 /var/www/html/magento/vendor/magento/framework/View/Element/AbstractBlock.php(1111): Magento\Framework\View\Element\Template->_toHtml()
#4 /var/www/html/magento/vendor/magento/framework/View/Element/AbstractBlock.php(1115): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
#5 /var/www/html/magento/vendor/magento/framework/View/Element/AbstractBlock.php(675): Magento\Framework\View\Element\AbstractBlock->_loadCache()
#6 /var/www/html/magento/vendor/magento/module-email/Model/Template/Filter.php(426): Magento\Framework\View\Element\AbstractBlock->toHtml()
#7 [internal function]: Magento\Email\Model\Template\Filter->blockDirective(Array)
#8 /var/www/html/magento/vendor/magento/framework/Filter/DirectiveProcessor/LegacyDirective.php(42): ReflectionMethod->invokeArgs(Object(Magento\Widget\Model\Template\Filter), Array)
#9 /var/www/html/magento/vendor/magento/framework/Filter/Template.php(184): Magento\Framework\Filter\DirectiveProcessor\LegacyDirective->process(Array, Object(Magento\Widget\Model\Template\Filter), Array)
#10 /var/www/html/magento/vendor/magento/module-email/Model/Template/Filter.php(1080): Magento\Framework\Filter\Template->filter('<div style=

Null pointer de-reference, but like I said I don't know Magento code...

 

Help please, thanks,

Evelyn

Highlighted

Re: 2.3.5-P1 to 2.4.0 Contact Form Error

I'm seeing the exact same view on the broken contact page.

 

There is now some discussion at github

https://github.com/magento/magento2/issues/29357