Dear Community,
I'm trying to introduce a feature in my website's contact form that allows the user to contact different e-mails depending on the subject.
This is the actual contact form:
I need an extra field named "Subject" with two options:
"General Discussion" - email1@domain.com
"Customer Issues" - email2@domain.com
How can I do that?
Thank you!
You need to add new field into your contact form.phtml
<select style="width:271px;" name="dep_subject" id="dep_subject">
<option value=""><?php echo __('') ?></option>
<option value=""><?php echo __('') ?></option>
</select>Override contact controller create di.xml file
file path :- app/code/Namespace/Yourmodule/etc/di.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> <preference for="Magento\Contact\Controller\Index\Post" type="Namespace\Yourmodule\Controller\Index\Post" /> </config>
Create Post.php or you copt Post.php file from Magento\Contact\Controller\Index\Post.php file
File path:- app/code/Namespace/Yourmodule/Controller/Index/Post.php
<?php
namespace Namespace\Yourmodule\Controller\Index;
class Post extends \Magento\Contact\Controller\Index
{
public function execute()
{
$post = $this->getRequest()->getPostValue();
if (!$post) {
$this->_redirect('*/*/');
return;
}
$this->inlineTranslation->suspend();
try {
$postObject = new \Magento\Framework\DataObject();
$postObject->setData($post);
$error = false;
if (!\Zend_Validate::is(trim($post['name']), 'NotEmpty')) {
$error = true;
}
if (!\Zend_Validate::is(trim($post['comment']), 'NotEmpty')) {
$error = true;
}
if (!\Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
$error = true;
}
if (\Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
$error = true;
}
if ($error) {
throw new \Exception();
}
// Write your suject to send email logic
} catch (\Exception $e) {
$this->inlineTranslation->resume();
$this->messageManager->addError(
__('We can\'t process your request right now. Sorry, that\'s all we know.')
);
$this->_redirect('contact/index');
return;
}
}
}
Do I have to create those folders named "Namespace", "Yourmodule", ...?
Hi Tierri,
This is for magento 2 because write question in magento 2 section but your site magento1.9.2 version
This solution is not for magento your current version.
Then how can i do in magento 1.9 version?
isn't there a solution about that?
Hey @xzxzxzxyy
The best way would be to ask the question in the right category on Magento 1 ![]()