I'm doing the front-end form in Magento 2, but I sucked this error, anyone can help me, please.
down is my code
in app / code / My / Module / Block / Contact.php
<? php
My Module Block namespace;
Contact class extends Magneto Framework View Element Template
{
/ **
* Build
*
* @param Magento Framework View Element Template Context $ context
* @param array $ data
* /
public function __constructed (
Magento Backend Block Template Context $ context,
array $ data = []
)
{
parent :: __ construct ($ context, $ data);
}
/ **
* Get URL action form for POST reservation request
*
* @return string
* /
Public function getFormAction ()
{
// companymodule is given in route.xml
// controller_name is the name of the folder inside the driver folder
// action is the name of the php file inside the previous controller_name folder
return & # 39; / mymodule / index / contact & # 39 ;;
// here controller_name is index, action is reserving
}
}
in app / code / My / Module / Controller / index / Contact.php
getRequest () -> getPost ();
if (! empty ($ post)) {
// Retrieve your form data
$ firstname = $ post['firstname'];
$ lastname = $ post['lastname'];
$ phone = $ post['phone'];
$ email = $ post['email'];
// Doing something with ...
// Show the validation message of the success form
$ this-> messageManager-> addSuccessMessage (& # 39; Submmition done! & # 39;);
// Redirect to your form page (or wherever you want ...)
$ resultRedirect = $ this-> resultFactory-> create (ResultFactory :: TYPE_REDIRECT);
$ resultRedirect-> setUrl (& # 39; / mymodule / index / stream_context_create () & # 39;);
returns $ resultRedirect;
}
// 2. GET request: Render the contact page
$ this -> _ view-> loadLayout ();
$ this -> _ view-> renderLayout ();
}
}
in app / code / My / Module / etc / frontend / route.xml
in app / code / My / Module / etc / module.xml
in app / code / My / Module / view / frontend / layout / mymodule_index_contact.xml
HTML Title - The contact form page.
in app / code / My / Module / view / frontend / templets / contact.phtml
Contact page
<form action = "getFormAction ()?> "method =" post ">
in app / code / My / Module / view / frontend / registration.php
<? php
Magento Framework Component ComponentRegistrar :: register (
Magento Framework Component ComponentRegistrar :: MODULE,
& # 39; My_module & # 39 ;,
__DIR__
);
And the error in the browser are
1 exception (s):
Exception # 0 (Magento Framework Exception ValidatorException): Invalid template file: & # 39; My_Module :: contact.phtml & # 39; in the module: & # 39; My_Module & # 39; Block name: & # 39; mymodule_contact & # 39;
Exception # 0 (Magento Framework Exception ValidatorException): Invalid template file: & # 39; My_Module :: contact.phtml & # 39; in the module: & # 39; My_Module & # 39; Block name: & # 39; mymodule_contact & # 39;
# 1 Magento Framework View Element Template -> _ toHtml () called in [lib/internal /Magento/Framework/View/Element/AbstractBlock.php:668]
# 2 Magento Framework View Element AbstractBlock-> toHtml () called in [lib/internal/Magento/Framework/View/Layout.php:557]
# 3 Magento Framework View Layout -> _ renderBlock () called in [lib/internal/Magento/Framework/View/Layout.php:533]
# 4 Magento Framework View Layout-> renderNonCachedElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
# 5 Magento Framework View Layout Interceptor-> renderNonCachedElement () called in [lib/internal/Magento/Framework/View/Layout.php:488]
# 6 Magento Framework View Layout-> renderElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
# 7 Magento Framework View Layout Interceptor-> renderElement () called in [lib/internal/Magento/Framework/View/Layout.php:585]
# 8 Magento Framework View Layout -> _ renderContainer () called in [lib/internal/Magento/Framework/View/Layout.php:535]
# 9 Magento Framework View Layout-> renderNonCachedElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
# 10 Magento Framework View Layout Interceptor-> renderNonCachedElement () called in [lib/internal/Magento/Framework/View/Layout.php:488]
# 11 Magento Framework View Layout-> renderElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
# 12 Magento Framework View Layout Interceptor-> renderElement () called in [lib/internal/Magento/Framework/View/Layout.php:585]
# 13 Magento Framework View Layout -> _ renderContainer () called in [lib/internal/Magento/Framework/View/Layout.php:535]
# 14 Magento Framework View Layout-> renderNonCachedElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
# 15 Magento Framework View Layout Interceptor-> renderNonCachedElement () called in [lib/internal/Magento/Framework/View/Layout.php:488]
# 16 Magento Framework View Layout-> renderElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
# 17 Magento Framework View Layout Interceptor-> renderElement () called in [lib/internal/Magento/Framework/View/Layout.php:585]
# 18 Magento Framework View Layout -> _ renderContainer () called in [lib/internal/Magento/Framework/View/Layout.php:535]
# 19 Magento Framework View Layout-> renderNonCachedElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
# 20 Magento Framework View Layout Interceptor-> renderNonCachedElement () called in [lib/internal/Magento/Framework/View/Layout.php:488]
# 21 Magento Framework View Layout-> renderElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
# 22 Magento Framework View Layout Interceptor-> renderElement () called in [lib/internal/Magento/Framework/View/Layout.php:585]
# 23 Magento Framework View Layout -> _ renderContainer () called in [lib/internal/Magento/Framework/View/Layout.php:535]
# 24 Magento Framework View Layout-> renderNonCachedElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
# 25 Magento Framework View Layout Interceptor-> renderNonCachedElement () called in [lib/internal/Magento/Framework/View/Layout.php:488]
# 26 Magento Framework View Layout-> renderElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
# 27 Magento Framework View Layout Interceptor-> renderElement () called in [lib/internal/Magento/Framework/View/Layout.php:585]
# 28 Magento Framework View Layout -> _ renderContainer () called in [lib/internal/Magento/Framework/View/Layout.php:535]
# 29 Magento Framework View Layout-> renderNonCachedElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
# 30 Magento Framework View Layout Interceptor-> renderNonCachedElement () called in [lib/internal/Magento/Framework/View/Layout.php:488]
# 31 Magento Framework View Layout-> renderElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
# 32 Magento Framework View Layout Interceptor-> renderElement () called in [lib/internal/Magento/Framework/View/Layout.php:585]
# 33 Magento Framework View Layout -> _ renderContainer () called in [lib/internal/Magento/Framework/View/Layout.php:535]
# 34 Magento Framework View Layout-> renderNonCachedElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
# 35 Magento Framework View Layout Interceptor-> renderNonCachedElement () called in [lib/internal/Magento/Framework/View/Layout.php:488]
# 36 Magento Framework View Layout-> renderElement () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
# 37 Magento Framework View Layout Interceptor-> renderElement () called in [lib/internal/Magento/Framework/View/Layout.php:954]
# 38 Magento Framework View Layout-> getOutput () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:58]
# 39 Magento Framework View Layout Interceptor -> ___ callParent () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:138]
# 40 Magento Framework View Layout Interceptor-> Magento Framework Interception {closing} () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:153]
# 41 Magento Framework View Layout Interceptor -> ___ callPlugins () called in [generated/code/Magento/Framework/View/Layout/Interceptor.php:494]
# 42 Magento Framework View Layout Interceptor-> getOutput () called in [lib/internal/Magento/Framework/View/Result/Page.php:258]
# 43 Magento Framework View Result Page-> render () called in [lib/internal/Magento/Framework/View/Result/Layout.php:171]
# 44 Magento Framework View Result Layout-> renderResult () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:58]
# 45 Magento Framework View Result Page Interceptor -> ___ callParent () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:138]
# 46 Magento Framework View Result Page Interceptor-> Magento Framework Interception {closing} () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:153]
# 47 Magento Framework View Result Page Interceptor -> ___ callPlugins () called in [generated/code/Magento/Framework/View/Result/Page/Interceptor.php:130]
# 48 Magento Framework View Result Page Interceptor-> renderResult () called in [lib/internal/Magento/Framework/App/View.php:221]
# 49 Magento Framework App View-> renderLayout () called in [app/code/My/Module/Controller/Index/Contact.php:40]
# 50 My Module Controller Index Contact-> execute () called in [generated/code/My/Module/Controller/Index/Contact/Interceptor.php:24]
# 51 My Module Controller Index Contact Interceptor-> execute () called in [lib/internal/Magento/Framework/App/Action/Action.php:108]
# 52 Magento Framework App Action Action-> dispatch () called in [lib/internal/Magento /Framework/Interception/Interceptor.php:58]
# 53 My Module Controller Index Contact Interceptor -> ___ callParent () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:138]
# 54 My Module Controller Index Contact Interceptor-> Magento Framework Interception {closing} () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:153]
# 55 My Module Controller Index Contact Interceptor -> ___ callPlugins () called in [generated/code/My/Module/Controller/Index/Contact/Interceptor.php:39]
# 56 My Module Controller Index Contact Interceptor-> dispatch () called in [lib/internal/Magento/Framework/App/FrontController.php:159]
# 57 Magento Framework App FrontController-> processRequest () called in [lib/internal/Magento/Framework/App/FrontController.php:99]
# 58 Magento Framework App FrontController-> dispatch () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:58]
# 59 Magento Framework App FrontController Interceptor -> ___ callParent () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:138]
# 60 Magento Framework App FrontController Interceptor-> Magento Framework Interception {closing} () called in [app/code/Magento/Store/App/FrontController/Plugin/RequestPreprocessor.php:94]
# 61 Magento Store App FrontController Plugin RequestPreprocessor-> aroundDispatch () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:135]
# 62 Magento Framework App FrontController Interceptor-> Magento Framework Interception {closing} () called in [app/code/Magento/PageCache/Model/App/FrontController/BuiltinPlugin.php:73]
# 63 Magento PageCache Model App FrontController BuiltinPlugin-> aroundDispatch () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:135]
# 64 Magento Framework App FrontController Interceptor-> Magento Framework Interception {closing} () called in [lib/internal/Magento/Framework/Interception/Interceptor.php:153]
# 65 Magento Framework App FrontController Interceptor -> ___ callPlugins () called in [generated/code/Magento/Framework/App/FrontController/Interceptor.php:26]
# 66 Magento Framework App FrontController Interceptor-> dispatch () called in [lib/internal/Magento/Framework/App/Http.php:136]
# 67 Magento Framework App Http-> launch () called in [generated/code/Magento/Framework/App/Http/Interceptor.php:24]
# 68 Magento Framework App Http Interceptor-> launch () called in [lib/internal/Magento/Framework/App/Bootstrap.php:258]
# 69 Magento Framework App Bootstrap-> run () called in [index.php:39]