DSGVO Magento

How do you change the name field in the Magento 1 contact form from a required field to an optional field? The background to this is that, as part of the General Data Protection Regulation (GDPR), which came into effect in 2018, you may want to give users the option of sending a message to the shop operator without having to provide their name.

 

 First, we change the name field from a required field to an optional field in (adjust the package "econcess" and template "default" to your own requirements)

 

\app\design\frontend\econcess\default\template\contacts\form.phtml

 

so that the following code remains:

 

                    <label for="name"><?php echo Mage::helper('contacts')->__('Name') ?></label>

                    <div class="input-box">

                        <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text" type="text" />

                    </div>

 

That alone would of course be too easy. In addition, we still need to write a small extension that overrides the IndexController to allow an empty name field. In our case, this is the Econcess_Contacts extension. We make this known in

 

\app\etc\modules\Econcess_Contacts.xml

 

mit dem Inhalt

 

<?xml version="1.0"?>

<config>

    <modules>

        <Econcess_Contacts>

            <active>true</active>

            <codePool>local</codePool>

        </Econcess_Contacts>

    </modules>

</config>

 

Then we create the file 

 

\app\code\local\Econcess\Contacts\etc\config.xml

 

with the content

 

<config>

    <modules>

        <Econcess_Contacts>

            <version>1.0.0</version>

        </Econcess_Contacts>

    </modules>

            <frontend>

                        <routers>

                                    <contacts>

                                               <args>

                                                           <modules>

                                                                       <econcess_contacts before="Mage_Contacts">Econcess_Contacts</econcess_contacts>

                                                           </modules>

                                               </args>

                                    </contacts>

                        </routers>

            </frontend>

</config>

 

and then the file

 

\app\code\local\Econcess\Contacts\controllers\IndexController.php

 

with the following content 

 

<?php

require_once(Mage::getModuleDir('controllers','Mage_Contacts').DS.'IndexController.php');

class Econcess_Contacts_IndexController extends Mage_Contacts_IndexController

{

    public function postAction()

    {

        $post = $this->getRequest()->getPost();

        if ( $post ) {

            $translate = Mage::getSingleton('core/translate');

            /* @var $translate Mage_Core_Model_Translate */

            $translate->setTranslateInline(false);

            try {

                $postObject = new Varien_Object();

                $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();

                }

                $mailTemplate = Mage::getModel('core/email_template');

                /* @var $mailTemplate Mage_Core_Model_Email_Template */

                $mailTemplate->setDesignConfig(array('area' => 'frontend'))

                    ->setReplyTo($post['email'])

                    ->sendTransactional(

                        Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),

                        Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),

                        Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),

                        null,

                        array('data' => $postObject)

                    );

                if (!$mailTemplate->getSentSuccess()) {

                    throw new Exception();

                }

                $translate->setTranslateInline(true);

                Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));

                $this->_redirect('*/*/');

                return;

            } catch (Exception $e) {

                $translate->setTranslateInline(true);

                Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));

                $this->_redirect('*/*/');

                return;

            }

        } else {

            $this->_redirect('*/*/');

        }

    }

}

 

So here, the boolean $error variable is simply left set to "false" when the name field is empty, because that validation is commented out.

 

That's it. Tested with Magento 1.9.1.0.