Showing results for 
Search instead for 
Did you mean: 

2.3.5-P1 to 2.4.0 Contact Form Error

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

Any thought on what the issue could be?


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.


Re: 2.3.5-P1 to 2.4.0 Contact Form Error

No, I haven't overwritten any core files

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 ! Smiley Happy

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

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:


Based on that context, looking at the code in:


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

            <div class="control">
                <input name="name" 
                       title="<?= $block->escapeHtmlAttr(__('Name')) ?>" 
                       value="<?= $block->escapeHtmlAttr($viewModel->getUserName
()) ?>" 

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>
<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.




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
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,


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

Re: 2.3.5-P1 to 2.4.0 Contact Form Error

Yea I filed that bug report.  Basically it is an undocumented incompatibility between versions.


It should have appeared in the release notes as a Backward Incompatible Change.

And they should have provided a new example, that reflects the code changes, for how to customize the Contact Us.


Re: 2.3.5-P1 to 2.4.0 Contact Form Error

what is the code of regulator which is heading off to that specific page ? 

whataburger survey code