Overriding the contact form module gets the fatal error in Magento2.2.5? Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?M2 di compiling throws error because of incompatible argument typemagento 2 captcha not rendering if I override layout xmlMagento 2 : Problem while adding custom button order view page?Magento 2 Add new field to Magento_User admin formMagento2 extend core block constructorMagento 2.3 Can't view module's front end page output?Magento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Email template for contact form in magento2.2.5?Stop sending contact form emails to consumer in magento2.2.5?How to remove default contact form validation in Magento2.2.5?

How to react to hostile behavior from a senior developer?

Why did the IBM 650 use bi-quinary?

ListPlot join points by nearest neighbor rather than order

Why did the Falcon Heavy center core fall off the ASDS OCISLY barge?

What causes the vertical darker bands in my photo?

Apollo command module space walk?

First console to have temporary backward compatibility

When do you get frequent flier miles - when you buy, or when you fly?

Why do people hide their license plates in the EU?

When were vectors invented?

Why did the rest of the Eastern Bloc not invade Yugoslavia?

3 doors, three guards, one stone

porting install scripts : can rpm replace apt?

What exactly is a "Meth" in Altered Carbon?

The logistics of corpse disposal

Why are both D and D# fitting into my E minor key?

Should I discuss the type of campaign with my players?

Echoing a tail command produces unexpected output?

Do I really need recursive chmod to restrict access to a folder?

Why was the term "discrete" used in discrete logarithm?

Output the ŋarâþ crîþ alphabet song without using (m)any letters

Dating a Former Employee

What does an IRS interview request entail when called in to verify expenses for a sole proprietor small business?

Why am I getting the error "non-boolean type specified in a context where a condition is expected" for this request?



Overriding the contact form module gets the fatal error in Magento2.2.5?



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?M2 di compiling throws error because of incompatible argument typemagento 2 captcha not rendering if I override layout xmlMagento 2 : Problem while adding custom button order view page?Magento 2 Add new field to Magento_User admin formMagento2 extend core block constructorMagento 2.3 Can't view module's front end page output?Magento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Email template for contact form in magento2.2.5?Stop sending contact form emails to consumer in magento2.2.5?How to remove default contact form validation in Magento2.2.5?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have overriden the contact form module, after disabling the default contact form validation and apply my custom validation gets the following error:




Fatal error: Uncaught TypeError: Argument 1 passed to
MagentoFrameworkDataObject::__construct() must be of the type array,
null given, called in
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php
on line 119 and defined in
/var/www/html/magento/vendor/magento/framework/DataObject.php:38 Stack
trace: #0
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php(119):
MagentoFrameworkDataObject->__construct(NULL) #1
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php(84):
AmyContactformControllerIndexPost->sendEmail(NULL) #2
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(58):
AmyContactformControllerIndexPost->execute() #3
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(138):
AmyContactformControllerIndexPostInterceptor->___callParent('execute',
Array) #4
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(153):
AmyContactformControllerIndexPostInterceptor->MagentoFramewor in
/var/www/html/magento/vendor/magento/framework/DataObject.php on line
38




Here is my code:




/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php




:



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

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
use MagentoNewsletterModelSubscriberFactory;

class Post extends MagentoContactControllerIndexPost

/**
* @var DataPersistorInterface
*/
private $dataPersistor;

/**
* @var Context
*/
private $context;

/**
* @var MailInterface
*/
private $mail;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var MagentoNewsletterModelSubscriberFactory
*/
protected $subscriberFactory;


/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
SubscriberFactory $subscriberFactory,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->subscriberFactory = $subscriberFactory;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()


if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());

// subscribe to newsletter---------CODE START
if ($this->getRequest()->getParam('is_subscribed', false))
$this->subscriberFactory->create()->subscribe($this->getRequest()->getParam('email'));

// subscribe to newsletter---------CODE END


$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

// $request = $this->getRequest();
// if (trim($request->getParam('name')) === '')
// throw new LocalizedException(__('Name is missing'));
//
// if (trim($request->getParam('lastname')) === '')
// throw new LocalizedException(__('LastName is missing'));
//
// if (trim($request->getParam('address1')) === '')
// throw new LocalizedException(__('Address1 is missing'));
//
// if (trim($request->getParam('address2')) === '')
// throw new LocalizedException(__('Address2 is missing'));
//
// if (trim($request->getParam('city')) === '')
// throw new LocalizedException(__('City is missing'));
//
// if (trim($request->getParam('stateprovince')) === '')
// throw new LocalizedException(__('State is missing'));
//
// if (trim($request->getParam('zipcode')) === '')
// throw new LocalizedException(__('Zipcode is missing'));
//
// if (trim($request->getParam('subject')) === '')
// throw new LocalizedException(__('Subject is missing'));
//
// if (trim($request->getParam('comment')) === '')
// throw new LocalizedException(__('Comment is missing'));
//

// if (false === strpos($request->getParam('email'), '@'))
// throw new LocalizedException(__('Invalid email address'));
//
// if (trim($request->getParam('hideit')) !== '')
// throw new Exception();
//
//return $request->getParams();





/var/www/html/magento/app/code/Amy/Contactform/view/frontend/templates/form.phtml:




<?php

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$states = $objectManager->create('MagentoDirectoryModelRegionFactory')
->create()->getCollection()->addFieldToFilter('country_id','US');
//echo "<pre>";
//print_r($states->getData());
$regionList = $block->getRegion();
//$countryList = $block->getCountry();
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile
/** @var MagentoContactBlockContactForm $block */
?>
<div class="container">
<div class="row margincontrol">
<!-- <form class="form contact" 22-3-19-->
<form class=""
action="<?= $block->escapeUrl($block->getFormAction()) ?>"
id="contact-form"
method="post"
data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>">
<fieldset class="fieldset">
<div class="legend empty_class"><h2 class="header_fontst"><?= $block->escapeHtml(__('Contact Us')) ?></h2></div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field name required">
<label class="label" for="name"><span class="font_app"><?= $block->escapeHtml(__('First Name')) ?></span></label>
<div class="control">
<input name="name" id="name" title="<?= $block->escapeHtmlAttr(__('Name')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('name') ?: $this->helper('MagentoContactHelperData')->getUserName()) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field lastname required">
<label class="label boxspaing" for="last_name"><span class="font_app"><?= $block->escapeHtml(__('Last Name')) ?></span></label>
<div class="control boxspaing">
<input name="last_name" id="last_name" title="<?= $block->escapeHtmlAttr(__('LastName')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('lastname') ?: $this->helper('MagentoContactHelperData')->getUserName()) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field email required">
<label class="label" for="email"><span class="font_app"><?= $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<input name="email" id="email" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('email') ?: $this->helper('MagentoContactHelperData')->getUserEmail()) ?>" class="input-text" type="email"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field telephone required">
<label class="label boxspaing" for="telephone"><span class="font_app"><?= $block->escapeHtml(__('Telephone')) ?></span></label>
<div class="control boxspaing">
<input name="telephone" id="telephone" title="<?= $block->escapeHtmlAttr(__('Phone Number')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('telephone')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field address1 required">
<label class="label" for="address1"><span class="font_app"><?= $block->escapeHtml(__('Address1')) ?></span></label>
<div class="control">
<input name="address1" id="address1" title="<?= $block->escapeHtmlAttr(__('Address1')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('address1')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field address2">
<label class="label boxspaing" for="address2"><span class="font_app"><?= $block->escapeHtml(__('Address2')) ?></span></label>
<div class="control boxspaing">
<input name="address2" id="address2" title="<?= $block->escapeHtmlAttr(__('Address2')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('address2')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field city required">
<label class="label" for="city"><span class="font_app"><?= $block->escapeHtml(__('City')) ?></span></label>
<div class="control">
<input name="city" id="city" title="<?= $block->escapeHtmlAttr(__('City')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('city')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field stateprovince required">
<label class="label boxspaing" for="stateprovince"><span class="font_app"><?php echo __('State / Province') ?></span></label>
<div class="control boxspaing">
<select class="select_img" name="stateprovince" id ="stateprovince" class="input-text" type="text">
<option selected value>Select One</option>
<?php foreach ($states as $_state):?>
<option value="<?php echo $_state->getName();?>"><?php echo $_state->getName();?></option>
<?php endforeach;?>
</select>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field zipcode required">
<label class="label" for="zipcode"><span class="font_app"><?= $block->escapeHtml(__('Zipcode')) ?></span></label>
<div class="control">
<input name="zipcode" id="zipcode" title="<?= $block->escapeHtmlAttr(__('Zipcode')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('zipcode')) ?>" class="input-text" type="text"/>
</div>
</div>


<div class="col-sm-12 col-md-6 col-lg-6 hightposition field subject required">
<label class="label boxspaing" for="subject"><span class="font_app"><?= $block->escapeHtml(__('Subject')) ?></span></label>
<div class="control boxspaing">
<select name="subject" id="subject" title="<?= $block->escapeHtmlAttr(__('Subject')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('subject')) ?>" class="input-text" type="text"/>

<option selected value>Select One</option>
<option value="Repair">Repair</option>
<option value="Warranty">Warranty</option>
<option value="General Feedback">General Feedback</option>
</select>
</div>
</div>

<div class="col-sm-12 col-md-12 col-lg-12 field comment required" style="width: 100% !important;">
<label class="label messagees" for="comment"><span class="font_app"><?= $block->escapeHtml(__('Message')) ?></span></label>

<textarea name="comment" id="comment" title="<?= $block->escapeHtmlAttr(__('What’s on your mind?')) ?>" class="input-text" type="text"><?= $block->escapeHtml($this->helper('MagentoContactHelperData')->getPostValue('comment')) ?></textarea>

</div>

<!--design code start -->
<div class="col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 5px;">
<div class="control submitt">
<!-- <input type="checkbox" name="" value="on"> -->
<label class="submit_head phone_rig">
<input type="checkbox" name="is_subscribed" id ="is_subscribed" checked="checked" value="on">Subscribe to receive exciting news.
<span class="submit_class"></span>
</label>
</div>

</div>
<div class="col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 5px;">
<div class="control submitt">
<!-- <input type="checkbox" name="" value="on"> -->
<label class="submit_head phone_rig">
<input type="checkbox" name="retailer" value="on" id="retailer"> Yes, I would like my information sent to an authorized retailer in my area.
<span class="submit_class"></span>
</label>
</div>

</div>
<div class="clearfix style_bottom"></div>
<!-- dev code -->

<?= $block->getChildHtml('form.additional.info') ?>

<div class="col-sm-12 col-md-12 col-lg-12">
<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>
</div>

</fieldset>

</form>
</div>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script type="text/javascript">
require([
'jquery'
], function($)

jQuery(document).ready(function()

jQuery("#contact-form").validate(

rules:
name: "required",
last_name: "required",
email:
required: true,
email: true
,
telephone:
required:true,
number:true
,
address1: "required",
city: "required",
stateprovince: "required",
zipcode: "required",
subject: "required",
comment: "required"
,
messages:
name: "Please enter your First Name",
last_name: "Please enter your Last Name",
email: "Please enter a valid Email Address",
telephone:
required: "Please enter your Phone Number",
number:"Please enter numbers Only"
,
address1: "Please enter your Address",
city: "Please enter your City",
stateprovince: "Please enter your State/Province",
zipcode: "Please enter your Zipcode",
subject: "Please enter your Subject",
comment: "Please enter your Message"
,
);
);

);
</script>



/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php:




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

use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
use MagentoContactModelConfigInterface;

class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)

/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'Repair')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'General Feedback')
$emails = ['bbb@gmail.com','ccc@gmail.com']; // add your email list
else
$emails = ['aaa@gmail.com'];


$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();

$transport->sendMessage();
finally
$this->inlineTranslation->resume();





Any one Help me on this please..




/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml:




<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
<preference for="MagentoContactControllerIndexPost"
type="AmyContactformControllerIndexPost" />
</config>









share|improve this question
























  • did you execute di:compile command after overriding? and post your di.xml

    – Keyur Shah
    yesterday











  • I am overriding all the above 3 files.

    – Amy
    yesterday











  • Yes, I have executed di: compile..

    – Amy
    yesterday











  • I have updated my di.xml file

    – Amy
    yesterday











  • @Amy I think you better remove the null default for your logger LoggerInterface $logger = null omit the =null

    – magefms
    yesterday

















0















I have overriden the contact form module, after disabling the default contact form validation and apply my custom validation gets the following error:




Fatal error: Uncaught TypeError: Argument 1 passed to
MagentoFrameworkDataObject::__construct() must be of the type array,
null given, called in
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php
on line 119 and defined in
/var/www/html/magento/vendor/magento/framework/DataObject.php:38 Stack
trace: #0
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php(119):
MagentoFrameworkDataObject->__construct(NULL) #1
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php(84):
AmyContactformControllerIndexPost->sendEmail(NULL) #2
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(58):
AmyContactformControllerIndexPost->execute() #3
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(138):
AmyContactformControllerIndexPostInterceptor->___callParent('execute',
Array) #4
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(153):
AmyContactformControllerIndexPostInterceptor->MagentoFramewor in
/var/www/html/magento/vendor/magento/framework/DataObject.php on line
38




Here is my code:




/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php




:



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

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
use MagentoNewsletterModelSubscriberFactory;

class Post extends MagentoContactControllerIndexPost

/**
* @var DataPersistorInterface
*/
private $dataPersistor;

/**
* @var Context
*/
private $context;

/**
* @var MailInterface
*/
private $mail;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var MagentoNewsletterModelSubscriberFactory
*/
protected $subscriberFactory;


/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
SubscriberFactory $subscriberFactory,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->subscriberFactory = $subscriberFactory;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()


if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());

// subscribe to newsletter---------CODE START
if ($this->getRequest()->getParam('is_subscribed', false))
$this->subscriberFactory->create()->subscribe($this->getRequest()->getParam('email'));

// subscribe to newsletter---------CODE END


$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

// $request = $this->getRequest();
// if (trim($request->getParam('name')) === '')
// throw new LocalizedException(__('Name is missing'));
//
// if (trim($request->getParam('lastname')) === '')
// throw new LocalizedException(__('LastName is missing'));
//
// if (trim($request->getParam('address1')) === '')
// throw new LocalizedException(__('Address1 is missing'));
//
// if (trim($request->getParam('address2')) === '')
// throw new LocalizedException(__('Address2 is missing'));
//
// if (trim($request->getParam('city')) === '')
// throw new LocalizedException(__('City is missing'));
//
// if (trim($request->getParam('stateprovince')) === '')
// throw new LocalizedException(__('State is missing'));
//
// if (trim($request->getParam('zipcode')) === '')
// throw new LocalizedException(__('Zipcode is missing'));
//
// if (trim($request->getParam('subject')) === '')
// throw new LocalizedException(__('Subject is missing'));
//
// if (trim($request->getParam('comment')) === '')
// throw new LocalizedException(__('Comment is missing'));
//

// if (false === strpos($request->getParam('email'), '@'))
// throw new LocalizedException(__('Invalid email address'));
//
// if (trim($request->getParam('hideit')) !== '')
// throw new Exception();
//
//return $request->getParams();





/var/www/html/magento/app/code/Amy/Contactform/view/frontend/templates/form.phtml:




<?php

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$states = $objectManager->create('MagentoDirectoryModelRegionFactory')
->create()->getCollection()->addFieldToFilter('country_id','US');
//echo "<pre>";
//print_r($states->getData());
$regionList = $block->getRegion();
//$countryList = $block->getCountry();
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile
/** @var MagentoContactBlockContactForm $block */
?>
<div class="container">
<div class="row margincontrol">
<!-- <form class="form contact" 22-3-19-->
<form class=""
action="<?= $block->escapeUrl($block->getFormAction()) ?>"
id="contact-form"
method="post"
data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>">
<fieldset class="fieldset">
<div class="legend empty_class"><h2 class="header_fontst"><?= $block->escapeHtml(__('Contact Us')) ?></h2></div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field name required">
<label class="label" for="name"><span class="font_app"><?= $block->escapeHtml(__('First Name')) ?></span></label>
<div class="control">
<input name="name" id="name" title="<?= $block->escapeHtmlAttr(__('Name')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('name') ?: $this->helper('MagentoContactHelperData')->getUserName()) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field lastname required">
<label class="label boxspaing" for="last_name"><span class="font_app"><?= $block->escapeHtml(__('Last Name')) ?></span></label>
<div class="control boxspaing">
<input name="last_name" id="last_name" title="<?= $block->escapeHtmlAttr(__('LastName')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('lastname') ?: $this->helper('MagentoContactHelperData')->getUserName()) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field email required">
<label class="label" for="email"><span class="font_app"><?= $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<input name="email" id="email" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('email') ?: $this->helper('MagentoContactHelperData')->getUserEmail()) ?>" class="input-text" type="email"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field telephone required">
<label class="label boxspaing" for="telephone"><span class="font_app"><?= $block->escapeHtml(__('Telephone')) ?></span></label>
<div class="control boxspaing">
<input name="telephone" id="telephone" title="<?= $block->escapeHtmlAttr(__('Phone Number')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('telephone')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field address1 required">
<label class="label" for="address1"><span class="font_app"><?= $block->escapeHtml(__('Address1')) ?></span></label>
<div class="control">
<input name="address1" id="address1" title="<?= $block->escapeHtmlAttr(__('Address1')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('address1')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field address2">
<label class="label boxspaing" for="address2"><span class="font_app"><?= $block->escapeHtml(__('Address2')) ?></span></label>
<div class="control boxspaing">
<input name="address2" id="address2" title="<?= $block->escapeHtmlAttr(__('Address2')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('address2')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field city required">
<label class="label" for="city"><span class="font_app"><?= $block->escapeHtml(__('City')) ?></span></label>
<div class="control">
<input name="city" id="city" title="<?= $block->escapeHtmlAttr(__('City')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('city')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field stateprovince required">
<label class="label boxspaing" for="stateprovince"><span class="font_app"><?php echo __('State / Province') ?></span></label>
<div class="control boxspaing">
<select class="select_img" name="stateprovince" id ="stateprovince" class="input-text" type="text">
<option selected value>Select One</option>
<?php foreach ($states as $_state):?>
<option value="<?php echo $_state->getName();?>"><?php echo $_state->getName();?></option>
<?php endforeach;?>
</select>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field zipcode required">
<label class="label" for="zipcode"><span class="font_app"><?= $block->escapeHtml(__('Zipcode')) ?></span></label>
<div class="control">
<input name="zipcode" id="zipcode" title="<?= $block->escapeHtmlAttr(__('Zipcode')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('zipcode')) ?>" class="input-text" type="text"/>
</div>
</div>


<div class="col-sm-12 col-md-6 col-lg-6 hightposition field subject required">
<label class="label boxspaing" for="subject"><span class="font_app"><?= $block->escapeHtml(__('Subject')) ?></span></label>
<div class="control boxspaing">
<select name="subject" id="subject" title="<?= $block->escapeHtmlAttr(__('Subject')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('subject')) ?>" class="input-text" type="text"/>

<option selected value>Select One</option>
<option value="Repair">Repair</option>
<option value="Warranty">Warranty</option>
<option value="General Feedback">General Feedback</option>
</select>
</div>
</div>

<div class="col-sm-12 col-md-12 col-lg-12 field comment required" style="width: 100% !important;">
<label class="label messagees" for="comment"><span class="font_app"><?= $block->escapeHtml(__('Message')) ?></span></label>

<textarea name="comment" id="comment" title="<?= $block->escapeHtmlAttr(__('What’s on your mind?')) ?>" class="input-text" type="text"><?= $block->escapeHtml($this->helper('MagentoContactHelperData')->getPostValue('comment')) ?></textarea>

</div>

<!--design code start -->
<div class="col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 5px;">
<div class="control submitt">
<!-- <input type="checkbox" name="" value="on"> -->
<label class="submit_head phone_rig">
<input type="checkbox" name="is_subscribed" id ="is_subscribed" checked="checked" value="on">Subscribe to receive exciting news.
<span class="submit_class"></span>
</label>
</div>

</div>
<div class="col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 5px;">
<div class="control submitt">
<!-- <input type="checkbox" name="" value="on"> -->
<label class="submit_head phone_rig">
<input type="checkbox" name="retailer" value="on" id="retailer"> Yes, I would like my information sent to an authorized retailer in my area.
<span class="submit_class"></span>
</label>
</div>

</div>
<div class="clearfix style_bottom"></div>
<!-- dev code -->

<?= $block->getChildHtml('form.additional.info') ?>

<div class="col-sm-12 col-md-12 col-lg-12">
<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>
</div>

</fieldset>

</form>
</div>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script type="text/javascript">
require([
'jquery'
], function($)

jQuery(document).ready(function()

jQuery("#contact-form").validate(

rules:
name: "required",
last_name: "required",
email:
required: true,
email: true
,
telephone:
required:true,
number:true
,
address1: "required",
city: "required",
stateprovince: "required",
zipcode: "required",
subject: "required",
comment: "required"
,
messages:
name: "Please enter your First Name",
last_name: "Please enter your Last Name",
email: "Please enter a valid Email Address",
telephone:
required: "Please enter your Phone Number",
number:"Please enter numbers Only"
,
address1: "Please enter your Address",
city: "Please enter your City",
stateprovince: "Please enter your State/Province",
zipcode: "Please enter your Zipcode",
subject: "Please enter your Subject",
comment: "Please enter your Message"
,
);
);

);
</script>



/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php:




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

use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
use MagentoContactModelConfigInterface;

class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)

/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'Repair')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'General Feedback')
$emails = ['bbb@gmail.com','ccc@gmail.com']; // add your email list
else
$emails = ['aaa@gmail.com'];


$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();

$transport->sendMessage();
finally
$this->inlineTranslation->resume();





Any one Help me on this please..




/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml:




<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
<preference for="MagentoContactControllerIndexPost"
type="AmyContactformControllerIndexPost" />
</config>









share|improve this question
























  • did you execute di:compile command after overriding? and post your di.xml

    – Keyur Shah
    yesterday











  • I am overriding all the above 3 files.

    – Amy
    yesterday











  • Yes, I have executed di: compile..

    – Amy
    yesterday











  • I have updated my di.xml file

    – Amy
    yesterday











  • @Amy I think you better remove the null default for your logger LoggerInterface $logger = null omit the =null

    – magefms
    yesterday













0












0








0








I have overriden the contact form module, after disabling the default contact form validation and apply my custom validation gets the following error:




Fatal error: Uncaught TypeError: Argument 1 passed to
MagentoFrameworkDataObject::__construct() must be of the type array,
null given, called in
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php
on line 119 and defined in
/var/www/html/magento/vendor/magento/framework/DataObject.php:38 Stack
trace: #0
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php(119):
MagentoFrameworkDataObject->__construct(NULL) #1
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php(84):
AmyContactformControllerIndexPost->sendEmail(NULL) #2
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(58):
AmyContactformControllerIndexPost->execute() #3
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(138):
AmyContactformControllerIndexPostInterceptor->___callParent('execute',
Array) #4
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(153):
AmyContactformControllerIndexPostInterceptor->MagentoFramewor in
/var/www/html/magento/vendor/magento/framework/DataObject.php on line
38




Here is my code:




/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php




:



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

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
use MagentoNewsletterModelSubscriberFactory;

class Post extends MagentoContactControllerIndexPost

/**
* @var DataPersistorInterface
*/
private $dataPersistor;

/**
* @var Context
*/
private $context;

/**
* @var MailInterface
*/
private $mail;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var MagentoNewsletterModelSubscriberFactory
*/
protected $subscriberFactory;


/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
SubscriberFactory $subscriberFactory,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->subscriberFactory = $subscriberFactory;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()


if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());

// subscribe to newsletter---------CODE START
if ($this->getRequest()->getParam('is_subscribed', false))
$this->subscriberFactory->create()->subscribe($this->getRequest()->getParam('email'));

// subscribe to newsletter---------CODE END


$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

// $request = $this->getRequest();
// if (trim($request->getParam('name')) === '')
// throw new LocalizedException(__('Name is missing'));
//
// if (trim($request->getParam('lastname')) === '')
// throw new LocalizedException(__('LastName is missing'));
//
// if (trim($request->getParam('address1')) === '')
// throw new LocalizedException(__('Address1 is missing'));
//
// if (trim($request->getParam('address2')) === '')
// throw new LocalizedException(__('Address2 is missing'));
//
// if (trim($request->getParam('city')) === '')
// throw new LocalizedException(__('City is missing'));
//
// if (trim($request->getParam('stateprovince')) === '')
// throw new LocalizedException(__('State is missing'));
//
// if (trim($request->getParam('zipcode')) === '')
// throw new LocalizedException(__('Zipcode is missing'));
//
// if (trim($request->getParam('subject')) === '')
// throw new LocalizedException(__('Subject is missing'));
//
// if (trim($request->getParam('comment')) === '')
// throw new LocalizedException(__('Comment is missing'));
//

// if (false === strpos($request->getParam('email'), '@'))
// throw new LocalizedException(__('Invalid email address'));
//
// if (trim($request->getParam('hideit')) !== '')
// throw new Exception();
//
//return $request->getParams();





/var/www/html/magento/app/code/Amy/Contactform/view/frontend/templates/form.phtml:




<?php

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$states = $objectManager->create('MagentoDirectoryModelRegionFactory')
->create()->getCollection()->addFieldToFilter('country_id','US');
//echo "<pre>";
//print_r($states->getData());
$regionList = $block->getRegion();
//$countryList = $block->getCountry();
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile
/** @var MagentoContactBlockContactForm $block */
?>
<div class="container">
<div class="row margincontrol">
<!-- <form class="form contact" 22-3-19-->
<form class=""
action="<?= $block->escapeUrl($block->getFormAction()) ?>"
id="contact-form"
method="post"
data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>">
<fieldset class="fieldset">
<div class="legend empty_class"><h2 class="header_fontst"><?= $block->escapeHtml(__('Contact Us')) ?></h2></div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field name required">
<label class="label" for="name"><span class="font_app"><?= $block->escapeHtml(__('First Name')) ?></span></label>
<div class="control">
<input name="name" id="name" title="<?= $block->escapeHtmlAttr(__('Name')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('name') ?: $this->helper('MagentoContactHelperData')->getUserName()) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field lastname required">
<label class="label boxspaing" for="last_name"><span class="font_app"><?= $block->escapeHtml(__('Last Name')) ?></span></label>
<div class="control boxspaing">
<input name="last_name" id="last_name" title="<?= $block->escapeHtmlAttr(__('LastName')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('lastname') ?: $this->helper('MagentoContactHelperData')->getUserName()) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field email required">
<label class="label" for="email"><span class="font_app"><?= $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<input name="email" id="email" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('email') ?: $this->helper('MagentoContactHelperData')->getUserEmail()) ?>" class="input-text" type="email"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field telephone required">
<label class="label boxspaing" for="telephone"><span class="font_app"><?= $block->escapeHtml(__('Telephone')) ?></span></label>
<div class="control boxspaing">
<input name="telephone" id="telephone" title="<?= $block->escapeHtmlAttr(__('Phone Number')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('telephone')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field address1 required">
<label class="label" for="address1"><span class="font_app"><?= $block->escapeHtml(__('Address1')) ?></span></label>
<div class="control">
<input name="address1" id="address1" title="<?= $block->escapeHtmlAttr(__('Address1')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('address1')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field address2">
<label class="label boxspaing" for="address2"><span class="font_app"><?= $block->escapeHtml(__('Address2')) ?></span></label>
<div class="control boxspaing">
<input name="address2" id="address2" title="<?= $block->escapeHtmlAttr(__('Address2')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('address2')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field city required">
<label class="label" for="city"><span class="font_app"><?= $block->escapeHtml(__('City')) ?></span></label>
<div class="control">
<input name="city" id="city" title="<?= $block->escapeHtmlAttr(__('City')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('city')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field stateprovince required">
<label class="label boxspaing" for="stateprovince"><span class="font_app"><?php echo __('State / Province') ?></span></label>
<div class="control boxspaing">
<select class="select_img" name="stateprovince" id ="stateprovince" class="input-text" type="text">
<option selected value>Select One</option>
<?php foreach ($states as $_state):?>
<option value="<?php echo $_state->getName();?>"><?php echo $_state->getName();?></option>
<?php endforeach;?>
</select>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field zipcode required">
<label class="label" for="zipcode"><span class="font_app"><?= $block->escapeHtml(__('Zipcode')) ?></span></label>
<div class="control">
<input name="zipcode" id="zipcode" title="<?= $block->escapeHtmlAttr(__('Zipcode')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('zipcode')) ?>" class="input-text" type="text"/>
</div>
</div>


<div class="col-sm-12 col-md-6 col-lg-6 hightposition field subject required">
<label class="label boxspaing" for="subject"><span class="font_app"><?= $block->escapeHtml(__('Subject')) ?></span></label>
<div class="control boxspaing">
<select name="subject" id="subject" title="<?= $block->escapeHtmlAttr(__('Subject')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('subject')) ?>" class="input-text" type="text"/>

<option selected value>Select One</option>
<option value="Repair">Repair</option>
<option value="Warranty">Warranty</option>
<option value="General Feedback">General Feedback</option>
</select>
</div>
</div>

<div class="col-sm-12 col-md-12 col-lg-12 field comment required" style="width: 100% !important;">
<label class="label messagees" for="comment"><span class="font_app"><?= $block->escapeHtml(__('Message')) ?></span></label>

<textarea name="comment" id="comment" title="<?= $block->escapeHtmlAttr(__('What’s on your mind?')) ?>" class="input-text" type="text"><?= $block->escapeHtml($this->helper('MagentoContactHelperData')->getPostValue('comment')) ?></textarea>

</div>

<!--design code start -->
<div class="col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 5px;">
<div class="control submitt">
<!-- <input type="checkbox" name="" value="on"> -->
<label class="submit_head phone_rig">
<input type="checkbox" name="is_subscribed" id ="is_subscribed" checked="checked" value="on">Subscribe to receive exciting news.
<span class="submit_class"></span>
</label>
</div>

</div>
<div class="col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 5px;">
<div class="control submitt">
<!-- <input type="checkbox" name="" value="on"> -->
<label class="submit_head phone_rig">
<input type="checkbox" name="retailer" value="on" id="retailer"> Yes, I would like my information sent to an authorized retailer in my area.
<span class="submit_class"></span>
</label>
</div>

</div>
<div class="clearfix style_bottom"></div>
<!-- dev code -->

<?= $block->getChildHtml('form.additional.info') ?>

<div class="col-sm-12 col-md-12 col-lg-12">
<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>
</div>

</fieldset>

</form>
</div>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script type="text/javascript">
require([
'jquery'
], function($)

jQuery(document).ready(function()

jQuery("#contact-form").validate(

rules:
name: "required",
last_name: "required",
email:
required: true,
email: true
,
telephone:
required:true,
number:true
,
address1: "required",
city: "required",
stateprovince: "required",
zipcode: "required",
subject: "required",
comment: "required"
,
messages:
name: "Please enter your First Name",
last_name: "Please enter your Last Name",
email: "Please enter a valid Email Address",
telephone:
required: "Please enter your Phone Number",
number:"Please enter numbers Only"
,
address1: "Please enter your Address",
city: "Please enter your City",
stateprovince: "Please enter your State/Province",
zipcode: "Please enter your Zipcode",
subject: "Please enter your Subject",
comment: "Please enter your Message"
,
);
);

);
</script>



/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php:




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

use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
use MagentoContactModelConfigInterface;

class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)

/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'Repair')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'General Feedback')
$emails = ['bbb@gmail.com','ccc@gmail.com']; // add your email list
else
$emails = ['aaa@gmail.com'];


$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();

$transport->sendMessage();
finally
$this->inlineTranslation->resume();





Any one Help me on this please..




/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml:




<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
<preference for="MagentoContactControllerIndexPost"
type="AmyContactformControllerIndexPost" />
</config>









share|improve this question
















I have overriden the contact form module, after disabling the default contact form validation and apply my custom validation gets the following error:




Fatal error: Uncaught TypeError: Argument 1 passed to
MagentoFrameworkDataObject::__construct() must be of the type array,
null given, called in
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php
on line 119 and defined in
/var/www/html/magento/vendor/magento/framework/DataObject.php:38 Stack
trace: #0
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php(119):
MagentoFrameworkDataObject->__construct(NULL) #1
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php(84):
AmyContactformControllerIndexPost->sendEmail(NULL) #2
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(58):
AmyContactformControllerIndexPost->execute() #3
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(138):
AmyContactformControllerIndexPostInterceptor->___callParent('execute',
Array) #4
/var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(153):
AmyContactformControllerIndexPostInterceptor->MagentoFramewor in
/var/www/html/magento/vendor/magento/framework/DataObject.php on line
38




Here is my code:




/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php




:



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

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
use MagentoNewsletterModelSubscriberFactory;

class Post extends MagentoContactControllerIndexPost

/**
* @var DataPersistorInterface
*/
private $dataPersistor;

/**
* @var Context
*/
private $context;

/**
* @var MailInterface
*/
private $mail;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var MagentoNewsletterModelSubscriberFactory
*/
protected $subscriberFactory;


/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
SubscriberFactory $subscriberFactory,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->subscriberFactory = $subscriberFactory;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()


if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());

// subscribe to newsletter---------CODE START
if ($this->getRequest()->getParam('is_subscribed', false))
$this->subscriberFactory->create()->subscribe($this->getRequest()->getParam('email'));

// subscribe to newsletter---------CODE END


$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

// $request = $this->getRequest();
// if (trim($request->getParam('name')) === '')
// throw new LocalizedException(__('Name is missing'));
//
// if (trim($request->getParam('lastname')) === '')
// throw new LocalizedException(__('LastName is missing'));
//
// if (trim($request->getParam('address1')) === '')
// throw new LocalizedException(__('Address1 is missing'));
//
// if (trim($request->getParam('address2')) === '')
// throw new LocalizedException(__('Address2 is missing'));
//
// if (trim($request->getParam('city')) === '')
// throw new LocalizedException(__('City is missing'));
//
// if (trim($request->getParam('stateprovince')) === '')
// throw new LocalizedException(__('State is missing'));
//
// if (trim($request->getParam('zipcode')) === '')
// throw new LocalizedException(__('Zipcode is missing'));
//
// if (trim($request->getParam('subject')) === '')
// throw new LocalizedException(__('Subject is missing'));
//
// if (trim($request->getParam('comment')) === '')
// throw new LocalizedException(__('Comment is missing'));
//

// if (false === strpos($request->getParam('email'), '@'))
// throw new LocalizedException(__('Invalid email address'));
//
// if (trim($request->getParam('hideit')) !== '')
// throw new Exception();
//
//return $request->getParams();





/var/www/html/magento/app/code/Amy/Contactform/view/frontend/templates/form.phtml:




<?php

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$states = $objectManager->create('MagentoDirectoryModelRegionFactory')
->create()->getCollection()->addFieldToFilter('country_id','US');
//echo "<pre>";
//print_r($states->getData());
$regionList = $block->getRegion();
//$countryList = $block->getCountry();
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile
/** @var MagentoContactBlockContactForm $block */
?>
<div class="container">
<div class="row margincontrol">
<!-- <form class="form contact" 22-3-19-->
<form class=""
action="<?= $block->escapeUrl($block->getFormAction()) ?>"
id="contact-form"
method="post"
data-hasrequired="<?= $block->escapeHtmlAttr(__('* Required Fields')) ?>">
<fieldset class="fieldset">
<div class="legend empty_class"><h2 class="header_fontst"><?= $block->escapeHtml(__('Contact Us')) ?></h2></div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field name required">
<label class="label" for="name"><span class="font_app"><?= $block->escapeHtml(__('First Name')) ?></span></label>
<div class="control">
<input name="name" id="name" title="<?= $block->escapeHtmlAttr(__('Name')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('name') ?: $this->helper('MagentoContactHelperData')->getUserName()) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field lastname required">
<label class="label boxspaing" for="last_name"><span class="font_app"><?= $block->escapeHtml(__('Last Name')) ?></span></label>
<div class="control boxspaing">
<input name="last_name" id="last_name" title="<?= $block->escapeHtmlAttr(__('LastName')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('lastname') ?: $this->helper('MagentoContactHelperData')->getUserName()) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field email required">
<label class="label" for="email"><span class="font_app"><?= $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<input name="email" id="email" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('email') ?: $this->helper('MagentoContactHelperData')->getUserEmail()) ?>" class="input-text" type="email"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field telephone required">
<label class="label boxspaing" for="telephone"><span class="font_app"><?= $block->escapeHtml(__('Telephone')) ?></span></label>
<div class="control boxspaing">
<input name="telephone" id="telephone" title="<?= $block->escapeHtmlAttr(__('Phone Number')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('telephone')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field address1 required">
<label class="label" for="address1"><span class="font_app"><?= $block->escapeHtml(__('Address1')) ?></span></label>
<div class="control">
<input name="address1" id="address1" title="<?= $block->escapeHtmlAttr(__('Address1')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('address1')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field address2">
<label class="label boxspaing" for="address2"><span class="font_app"><?= $block->escapeHtml(__('Address2')) ?></span></label>
<div class="control boxspaing">
<input name="address2" id="address2" title="<?= $block->escapeHtmlAttr(__('Address2')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('address2')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field city required">
<label class="label" for="city"><span class="font_app"><?= $block->escapeHtml(__('City')) ?></span></label>
<div class="control">
<input name="city" id="city" title="<?= $block->escapeHtmlAttr(__('City')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('city')) ?>" class="input-text" type="text"/>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field stateprovince required">
<label class="label boxspaing" for="stateprovince"><span class="font_app"><?php echo __('State / Province') ?></span></label>
<div class="control boxspaing">
<select class="select_img" name="stateprovince" id ="stateprovince" class="input-text" type="text">
<option selected value>Select One</option>
<?php foreach ($states as $_state):?>
<option value="<?php echo $_state->getName();?>"><?php echo $_state->getName();?></option>
<?php endforeach;?>
</select>
</div>
</div>

<div class="col-sm-12 col-md-6 col-lg-6 hightposition field zipcode required">
<label class="label" for="zipcode"><span class="font_app"><?= $block->escapeHtml(__('Zipcode')) ?></span></label>
<div class="control">
<input name="zipcode" id="zipcode" title="<?= $block->escapeHtmlAttr(__('Zipcode')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('zipcode')) ?>" class="input-text" type="text"/>
</div>
</div>


<div class="col-sm-12 col-md-6 col-lg-6 hightposition field subject required">
<label class="label boxspaing" for="subject"><span class="font_app"><?= $block->escapeHtml(__('Subject')) ?></span></label>
<div class="control boxspaing">
<select name="subject" id="subject" title="<?= $block->escapeHtmlAttr(__('Subject')) ?>" value="<?= $block->escapeHtmlAttr($this->helper('MagentoContactHelperData')->getPostValue('subject')) ?>" class="input-text" type="text"/>

<option selected value>Select One</option>
<option value="Repair">Repair</option>
<option value="Warranty">Warranty</option>
<option value="General Feedback">General Feedback</option>
</select>
</div>
</div>

<div class="col-sm-12 col-md-12 col-lg-12 field comment required" style="width: 100% !important;">
<label class="label messagees" for="comment"><span class="font_app"><?= $block->escapeHtml(__('Message')) ?></span></label>

<textarea name="comment" id="comment" title="<?= $block->escapeHtmlAttr(__('What’s on your mind?')) ?>" class="input-text" type="text"><?= $block->escapeHtml($this->helper('MagentoContactHelperData')->getPostValue('comment')) ?></textarea>

</div>

<!--design code start -->
<div class="col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 5px;">
<div class="control submitt">
<!-- <input type="checkbox" name="" value="on"> -->
<label class="submit_head phone_rig">
<input type="checkbox" name="is_subscribed" id ="is_subscribed" checked="checked" value="on">Subscribe to receive exciting news.
<span class="submit_class"></span>
</label>
</div>

</div>
<div class="col-sm-12 col-md-12 col-lg-12" style="margin-bottom: 5px;">
<div class="control submitt">
<!-- <input type="checkbox" name="" value="on"> -->
<label class="submit_head phone_rig">
<input type="checkbox" name="retailer" value="on" id="retailer"> Yes, I would like my information sent to an authorized retailer in my area.
<span class="submit_class"></span>
</label>
</div>

</div>
<div class="clearfix style_bottom"></div>
<!-- dev code -->

<?= $block->getChildHtml('form.additional.info') ?>

<div class="col-sm-12 col-md-12 col-lg-12">
<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>
</div>

</fieldset>

</form>
</div>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script type="text/javascript">
require([
'jquery'
], function($)

jQuery(document).ready(function()

jQuery("#contact-form").validate(

rules:
name: "required",
last_name: "required",
email:
required: true,
email: true
,
telephone:
required:true,
number:true
,
address1: "required",
city: "required",
stateprovince: "required",
zipcode: "required",
subject: "required",
comment: "required"
,
messages:
name: "Please enter your First Name",
last_name: "Please enter your Last Name",
email: "Please enter a valid Email Address",
telephone:
required: "Please enter your Phone Number",
number:"Please enter numbers Only"
,
address1: "Please enter your Address",
city: "Please enter your City",
stateprovince: "Please enter your State/Province",
zipcode: "Please enter your Zipcode",
subject: "Please enter your Subject",
comment: "Please enter your Message"
,
);
);

);
</script>



/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php:




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

use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
use MagentoContactModelConfigInterface;

class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);


/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)

/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'Repair')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'General Feedback')
$emails = ['bbb@gmail.com','ccc@gmail.com']; // add your email list
else
$emails = ['aaa@gmail.com'];


$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();

$transport->sendMessage();
finally
$this->inlineTranslation->resume();





Any one Help me on this please..




/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml:




<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
<preference for="MagentoContactControllerIndexPost"
type="AmyContactformControllerIndexPost" />
</config>






magento2 fatal-error form-validation contact-form






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Magento_Bhurio

435112




435112










asked yesterday









AmyAmy

35110




35110












  • did you execute di:compile command after overriding? and post your di.xml

    – Keyur Shah
    yesterday











  • I am overriding all the above 3 files.

    – Amy
    yesterday











  • Yes, I have executed di: compile..

    – Amy
    yesterday











  • I have updated my di.xml file

    – Amy
    yesterday











  • @Amy I think you better remove the null default for your logger LoggerInterface $logger = null omit the =null

    – magefms
    yesterday

















  • did you execute di:compile command after overriding? and post your di.xml

    – Keyur Shah
    yesterday











  • I am overriding all the above 3 files.

    – Amy
    yesterday











  • Yes, I have executed di: compile..

    – Amy
    yesterday











  • I have updated my di.xml file

    – Amy
    yesterday











  • @Amy I think you better remove the null default for your logger LoggerInterface $logger = null omit the =null

    – magefms
    yesterday
















did you execute di:compile command after overriding? and post your di.xml

– Keyur Shah
yesterday





did you execute di:compile command after overriding? and post your di.xml

– Keyur Shah
yesterday













I am overriding all the above 3 files.

– Amy
yesterday





I am overriding all the above 3 files.

– Amy
yesterday













Yes, I have executed di: compile..

– Amy
yesterday





Yes, I have executed di: compile..

– Amy
yesterday













I have updated my di.xml file

– Amy
yesterday





I have updated my di.xml file

– Amy
yesterday













@Amy I think you better remove the null default for your logger LoggerInterface $logger = null omit the =null

– magefms
yesterday





@Amy I think you better remove the null default for your logger LoggerInterface $logger = null omit the =null

– magefms
yesterday










1 Answer
1






active

oldest

votes


















0














Try this in your Post.php:



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

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
use MagentoNewsletterModelSubscriberFactory;

class Post extends MagentoContactControllerIndexPost
null $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
SubscriberFactory $subscriberFactory,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->contactsConfig = $contactsConfig;
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->subscriberFactory = $subscriberFactory;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()


if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());

// subscribe to newsletter---------CODE START
if ($this->getRequest()->getParam('is_subscribed', false))
$this->subscriberFactory->create()->subscribe($this->getRequest()->getParam('email'));

// subscribe to newsletter---------CODE END


$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

/**$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));

if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));

if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));

if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));

if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));

if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));

if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));

if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));

if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));


if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));

if (trim($request->getParam('hideit')) !== '')
throw new Exception();

return $request->getParams();*/







share|improve this answer

























  • I am still getting the same error in line ['data' => new DataObject($post)]. even after updating your answer.

    – Amy
    yesterday











  • which part is that in your post file?

    – magefms
    yesterday











  • is it same error or new error?

    – magefms
    yesterday











  • Yes, it is the same error. It is my post.php file.

    – Amy
    yesterday











  • @Amy try updated answer

    – magefms
    yesterday











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f270104%2foverriding-the-contact-form-module-gets-the-fatal-error-in-magento2-2-5%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try this in your Post.php:



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

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
use MagentoNewsletterModelSubscriberFactory;

class Post extends MagentoContactControllerIndexPost
null $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
SubscriberFactory $subscriberFactory,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->contactsConfig = $contactsConfig;
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->subscriberFactory = $subscriberFactory;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()


if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());

// subscribe to newsletter---------CODE START
if ($this->getRequest()->getParam('is_subscribed', false))
$this->subscriberFactory->create()->subscribe($this->getRequest()->getParam('email'));

// subscribe to newsletter---------CODE END


$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

/**$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));

if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));

if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));

if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));

if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));

if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));

if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));

if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));

if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));


if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));

if (trim($request->getParam('hideit')) !== '')
throw new Exception();

return $request->getParams();*/







share|improve this answer

























  • I am still getting the same error in line ['data' => new DataObject($post)]. even after updating your answer.

    – Amy
    yesterday











  • which part is that in your post file?

    – magefms
    yesterday











  • is it same error or new error?

    – magefms
    yesterday











  • Yes, it is the same error. It is my post.php file.

    – Amy
    yesterday











  • @Amy try updated answer

    – magefms
    yesterday















0














Try this in your Post.php:



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

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
use MagentoNewsletterModelSubscriberFactory;

class Post extends MagentoContactControllerIndexPost
null $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
SubscriberFactory $subscriberFactory,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->contactsConfig = $contactsConfig;
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->subscriberFactory = $subscriberFactory;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()


if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());

// subscribe to newsletter---------CODE START
if ($this->getRequest()->getParam('is_subscribed', false))
$this->subscriberFactory->create()->subscribe($this->getRequest()->getParam('email'));

// subscribe to newsletter---------CODE END


$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

/**$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));

if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));

if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));

if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));

if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));

if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));

if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));

if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));

if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));


if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));

if (trim($request->getParam('hideit')) !== '')
throw new Exception();

return $request->getParams();*/







share|improve this answer

























  • I am still getting the same error in line ['data' => new DataObject($post)]. even after updating your answer.

    – Amy
    yesterday











  • which part is that in your post file?

    – magefms
    yesterday











  • is it same error or new error?

    – magefms
    yesterday











  • Yes, it is the same error. It is my post.php file.

    – Amy
    yesterday











  • @Amy try updated answer

    – magefms
    yesterday













0












0








0







Try this in your Post.php:



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

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
use MagentoNewsletterModelSubscriberFactory;

class Post extends MagentoContactControllerIndexPost
null $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
SubscriberFactory $subscriberFactory,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->contactsConfig = $contactsConfig;
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->subscriberFactory = $subscriberFactory;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()


if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());

// subscribe to newsletter---------CODE START
if ($this->getRequest()->getParam('is_subscribed', false))
$this->subscriberFactory->create()->subscribe($this->getRequest()->getParam('email'));

// subscribe to newsletter---------CODE END


$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

/**$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));

if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));

if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));

if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));

if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));

if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));

if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));

if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));

if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));


if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));

if (trim($request->getParam('hideit')) !== '')
throw new Exception();

return $request->getParams();*/







share|improve this answer















Try this in your Post.php:



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

use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
use MagentoNewsletterModelSubscriberFactory;

class Post extends MagentoContactControllerIndexPost
null $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
SubscriberFactory $subscriberFactory,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->contactsConfig = $contactsConfig;
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->subscriberFactory = $subscriberFactory;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);


/**
* Post user question
*
* @return Redirect
*/
public function execute()


if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');

try
$this->sendEmail($this->validatedParams());

// subscribe to newsletter---------CODE START
if ($this->getRequest()->getParam('is_subscribed', false))
$this->subscriberFactory->create()->subscribe($this->getRequest()->getParam('email'));

// subscribe to newsletter---------CODE END


$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());

return $this->resultRedirectFactory->create()->setPath('contact/index');


/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)

$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);


/**
* @return bool
*/
private function isPostRequest()

/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());


/**
* @return array
* @throws Exception
*/
private function validatedParams()

/**$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));

if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));

if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));

if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));

if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));

if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));

if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));

if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));

if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));


if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));

if (trim($request->getParam('hideit')) !== '')
throw new Exception();

return $request->getParams();*/








share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









magefmsmagefms

2,7252528




2,7252528












  • I am still getting the same error in line ['data' => new DataObject($post)]. even after updating your answer.

    – Amy
    yesterday











  • which part is that in your post file?

    – magefms
    yesterday











  • is it same error or new error?

    – magefms
    yesterday











  • Yes, it is the same error. It is my post.php file.

    – Amy
    yesterday











  • @Amy try updated answer

    – magefms
    yesterday

















  • I am still getting the same error in line ['data' => new DataObject($post)]. even after updating your answer.

    – Amy
    yesterday











  • which part is that in your post file?

    – magefms
    yesterday











  • is it same error or new error?

    – magefms
    yesterday











  • Yes, it is the same error. It is my post.php file.

    – Amy
    yesterday











  • @Amy try updated answer

    – magefms
    yesterday
















I am still getting the same error in line ['data' => new DataObject($post)]. even after updating your answer.

– Amy
yesterday





I am still getting the same error in line ['data' => new DataObject($post)]. even after updating your answer.

– Amy
yesterday













which part is that in your post file?

– magefms
yesterday





which part is that in your post file?

– magefms
yesterday













is it same error or new error?

– magefms
yesterday





is it same error or new error?

– magefms
yesterday













Yes, it is the same error. It is my post.php file.

– Amy
yesterday





Yes, it is the same error. It is my post.php file.

– Amy
yesterday













@Amy try updated answer

– magefms
yesterday





@Amy try updated answer

– magefms
yesterday

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f270104%2foverriding-the-contact-form-module-gets-the-fatal-error-in-magento2-2-5%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?