Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BC] Added form key validation to Contacts form #3146

Merged
merged 2 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions app/code/core/Mage/Contacts/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,24 @@ public function postAction()
/** @var Mage_Core_Model_Translate $translate */
$translate->setTranslateInline(false);
try {
if (!$this->_validateFormKey()) {
Mage::throwException($this->__('Invalid Form Key. Please submit your request again.'));
}

$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')) {
} elseif (!Zend_Validate::is(trim($post['comment']), 'NotEmpty')) {
$error = true;
}

if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
} elseif (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
$error = true;
}

if ($error) {
throw new Exception();
Mage::throwException($this->__('Unable to submit your request. Please, try again later'));
fballiano marked this conversation as resolved.
Show resolved Hide resolved
}
$mailTemplate = Mage::getModel('core/email_template');
/** @var Mage_Core_Model_Email_Template $mailTemplate */
Expand All @@ -92,19 +91,22 @@ public function postAction()
);

if (!$mailTemplate->getSentSuccess()) {
throw new Exception();
Mage::throwException($this->__('Unable to submit your request. Please, try again later'));
addison74 marked this conversation as resolved.
Show resolved Hide resolved
}

$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.'));
Mage::getSingleton('customer/session')->addSuccess($this->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
$this->_redirect('*/*/');

return;
} catch (Exception $e) {
} catch (Mage_Core_Exception $e) {
$translate->setTranslateInline(true);

Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
Mage::logException($e);
Mage::getSingleton('customer/session')->addError($e->getMessage());
} catch (Throwable $e) {
Mage::logException($e);
Mage::getSingleton('customer/session')->addError($this->__('Unable to submit your request. Please, try again later'));
$this->_redirect('*/*/');
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<h1><?php echo Mage::helper('contacts')->__('Contact Us') ?></h1>
</div>
<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post">
<?php echo $this->getBlockHtml('formkey') ?>
<div class="fieldset">
<h2 class="legend"><?php echo Mage::helper('contacts')->__('Contact Information') ?></h2>
<ul class="form-list">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<h1><?php echo Mage::helper('contacts')->__('Contact Us') ?></h1>
</div>
<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post" class="scaffold-form">
<?php echo $this->getBlockHtml('formkey') ?>
<div class="fieldset">
<h2 class="legend"><?php echo Mage::helper('contacts')->__('Contact Information') ?></h2>
<p class="required"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>
Expand Down
3 changes: 2 additions & 1 deletion app/locale/en_US/Mage_Contacts.csv
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"Email Sender","Email Sender"
"Email Template","Email Template"
"Enable Contact Us","Enable Contact Us"
"Invalid Form Key. Please submit your request again.","Invalid Form Key. Please submit your request again."
"Name","Name"
"Send Emails To","Send Emails To"
"Submit","Submit"
"Telephone","Telephone"
"Unable to submit your request. Please, try again later","Unable to submit your request. Please, try again later"
"Unable to submit your request. Please, try again later","Unable to submit your request. Please, try again later."
fballiano marked this conversation as resolved.
Show resolved Hide resolved
"Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.","Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us."