Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 255 Vote(s) - 3.61 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prestashop: Disable contact form

#1
I would like to disable the contact form in my prestashop installation but there is no plugin to do so. Any suggestions how to do that?
Reply

#2
If You want to block just contact form but You want to display contact page You can put in override\controllers\front\ContactController.php:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

<?php
class ContactController extends ContactControllerCore
{
public function postProcess()
{
if (Tools::isSubmit('submitMessage'))
{die('Form disabled');}
else
parent::postProcess();
//return null;

}

}

<!-- end snippet -->
This will disable ability to send mails.

Then You can cut contact form from theme: /themes/YOUR-THEME/contact-form.tpl
to not display contact form at all

**After this You have to delete file /cache/class_index.php to refresh classes in prestashop.**
Reply

#3
Barto's solution can also be achieved without an override.

Create another module `contactformdisabler`

<!-- language: php -->

class ContactFormDisabler extends Module
{
public function __construct()
{
$this->name = 'contactformdisabler';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'whatever';

parent::__construct();

$this->displayName = $this->l('Contact form disabler');
$this->description = $this->l('Disables contact form submission.');
}

public function install()
{
return parent::install() && $this->registerHook('actionDispatcher');
}

public function hookActionDispatcher($params)
{
if ($params['controller_type'] === 1
&& $params['controller_class'] === 'ContactController'
&& Tools::isSubmit('submitMessage')) {
die('Contact form submission disabled');
}
}
}
Reply

#4
Depends what you mean by disabling contact form but here are few possibilities.

1. Modifying core contact controller (not recommended since you will lose custom code when updating Prestashop)

Open file `controllers/front/ContactController.php` and add this code inside the `ContactControllerCode` class.

<!-- language: php -->

public function init()
{
Tools::redirect('pagenotfound'); // redirect contact page to 404 page
}

2. Overriding contact controller

Create a new file `ContactController.php` and place it in folder `overrides/controllers/front/` and add the following code

<!-- language: php -->

class ContactController extends ContactControllerCore {
public function init()
{
Tools::redirect('pagenotfound'); // redirect contact page to 404 page
}
}

3. Create a small module

Create a new directory `contactpagedisabler` in folder `modules` and inside create a file `contactpagedisabler.php` and put this code in

<!-- language: php -->

class ContactPageDisabler extends Module
{
public function __construct()
{
$this->name = 'contactpagedisabler';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'whatever';

parent::__construct();

$this->displayName = $this->l('Contact page disabler');
$this->description = $this->l('Disables contact page.');
}

public function install()
{
return parent::install() && $this->registerHook('actionDispatcher');
}

// hook runs just after controller has been instantiated
public function hookActionDispatcher($params)
{
if ($params['controller_type'] === 1 && $params['controller_class'] === 'ContactController') {
Tools::redirect('pagenotfound'); // redirect contact page to 404 page
}
}
}

And then install this module from backoffice.

2nd option is simplest and it doesn't interfere with core files.

3rd option is probably overkill for such a small thing however it doesn't require overriding and if you or store manager ever needs the contact page back he can just disable the module from backoffice.
The module could also be expanded/modified with configuration page where you could for example get a list of all pages in store and let user decide which ones to enable/disable etc.

**Update April 2018**

Forget first two options and use third. Always use a module (if possible) when modifying your shop.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through