contactsformcaptcha - Version 1.3.0

Version Notes

Modified layout logic to show contact form with captcha when use different design themes. Added pre-filling contact form fields by a previous values when customer enter a incorrect captcha code.

Download this release

Release Info

Developer Magento Core Team
Extension contactsformcaptcha
Version 1.3.0
Comparing to
See all releases


Code changes from version 1.2.1 to 1.3.0

app/code/community/OlegKoval/ContactsFormCaptcha/controllers/IndexController.php CHANGED
@@ -30,6 +30,8 @@ class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexC
30
  public function indexAction() {
31
  $this->loadLayout();
32
 
 
 
33
  if (Mage::getStoreConfigFlag(self::XML_PATH_CFC_ENABLED)) {
34
  //include reCaptcha library
35
  require_once(Mage::getBaseDir('lib') . DS .'reCaptcha'. DS .'recaptchalib.php');
@@ -52,15 +54,10 @@ class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexC
52
  //small hack for language feature - because it's not working as described in documentation
53
  $captcha_code = str_replace('?k=', '?hl='. $lang .'&k=', $captcha_code);
54
 
55
- $this->getLayout()->getBlock('contactForm')->setTemplate('contactsformcaptcha/form.phtml')
56
- ->setFormAction(Mage::getUrl('*/*/post'))
57
- ->setCaptchaCode($captcha_code)
58
  ->setCaptchaTheme($theme)
59
  ->setCaptchaLang($lang);
60
  }
61
- else {
62
- $this->getLayout()->getBlock('contactForm')->setFormAction(Mage::getUrl('*/*/post'));
63
- }
64
 
65
  $this->_initLayoutMessages('customer/session');
66
  $this->_initLayoutMessages('catalog/session');
@@ -75,6 +72,10 @@ class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexC
75
  if (Mage::getStoreConfigFlag(self::XML_PATH_CFC_ENABLED)) {
76
  try {
77
  $post = $this->getRequest()->getPost();
 
 
 
 
78
  if ($post) {
79
  //include reCaptcha library
80
  require_once(Mage::getBaseDir('lib') . DS .'reCaptcha'. DS .'recaptchalib.php');
@@ -87,6 +88,8 @@ class OlegKoval_ContactsFormCaptcha_IndexController extends Mage_Contacts_IndexC
87
  if (!$captcha->is_valid) {
88
  throw new Exception($this->__("The reCAPTCHA wasn't entered correctly. Go back and try it again."), 1);
89
  }
 
 
90
  }
91
  else {
92
  throw new Exception('', 1);
30
  public function indexAction() {
31
  $this->loadLayout();
32
 
33
+ $this->getLayout()->getBlock('contactForm')->setFormAction(Mage::getUrl('*/*/post'));
34
+
35
  if (Mage::getStoreConfigFlag(self::XML_PATH_CFC_ENABLED)) {
36
  //include reCaptcha library
37
  require_once(Mage::getBaseDir('lib') . DS .'reCaptcha'. DS .'recaptchalib.php');
54
  //small hack for language feature - because it's not working as described in documentation
55
  $captcha_code = str_replace('?k=', '?hl='. $lang .'&k=', $captcha_code);
56
 
57
+ $this->getLayout()->getBlock('contactForm')->setCaptchaCode($captcha_code)
 
 
58
  ->setCaptchaTheme($theme)
59
  ->setCaptchaLang($lang);
60
  }
 
 
 
61
 
62
  $this->_initLayoutMessages('customer/session');
63
  $this->_initLayoutMessages('catalog/session');
72
  if (Mage::getStoreConfigFlag(self::XML_PATH_CFC_ENABLED)) {
73
  try {
74
  $post = $this->getRequest()->getPost();
75
+ $formData = new Varien_Object();
76
+ $formData->setData($post);
77
+ Mage::getSingleton('core/session')->setData('contactForm', $formData);
78
+
79
  if ($post) {
80
  //include reCaptcha library
81
  require_once(Mage::getBaseDir('lib') . DS .'reCaptcha'. DS .'recaptchalib.php');
88
  if (!$captcha->is_valid) {
89
  throw new Exception($this->__("The reCAPTCHA wasn't entered correctly. Go back and try it again."), 1);
90
  }
91
+
92
+ Mage::getSingleton('core/session')->unsetData('contactForm');
93
  }
94
  else {
95
  throw new Exception('', 1);
app/code/community/OlegKoval/ContactsFormCaptcha/etc/config.xml CHANGED
@@ -12,7 +12,7 @@
12
  <config>
13
  <modules>
14
  <OlegKoval_ContactsFormCaptcha>
15
- <version>1.2.0</version>
16
  <depends>
17
  <Mage_Contacts/>
18
  </depends>
@@ -52,6 +52,13 @@
52
  </OlegKoval_ContactsFormCaptcha>
53
  </modules>
54
  </translate>
 
 
 
 
 
 
 
55
  </frontend>
56
 
57
  <adminhtml>
12
  <config>
13
  <modules>
14
  <OlegKoval_ContactsFormCaptcha>
15
+ <version>1.3.0</version>
16
  <depends>
17
  <Mage_Contacts/>
18
  </depends>
52
  </OlegKoval_ContactsFormCaptcha>
53
  </modules>
54
  </translate>
55
+ <layout>
56
+ <updates>
57
+ <contactsformcaptcha module="OlegKoval_ContactsFormCaptcha">
58
+ <file>contactsformcaptcha.xml</file>
59
+ </contactsformcaptcha>
60
+ </updates>
61
+ </layout>
62
  </frontend>
63
 
64
  <adminhtml>
app/design/frontend/base/default/layout/contactsformcaptcha.xml CHANGED
@@ -10,17 +10,11 @@
10
  */
11
  -->
12
  <layout version="0.1.0">
13
- <contactsformcaptcha_index_index translate="label">
14
- <label>Contact Us Form</label>
15
- <reference name="head">
16
- <action method="setTitle" translate="title" module="contacts"><title>Contact Us</title></action>
17
- </reference>
18
- <reference name="root">
19
- <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
20
- <action method="setHeaderTitle" translate="title" module="contacts"><title>Contact Us</title></action>
21
- </reference>
22
  <reference name="content">
23
- <block type="core/template" name="contactsFormCaptcha" template="contactsformcaptcha/form.phtml"/>
 
 
24
  </reference>
25
- </contactsformcaptcha_index_index>
26
- </layout>
10
  */
11
  -->
12
  <layout version="0.1.0">
13
+ <contacts_index_index>
 
 
 
 
 
 
 
 
14
  <reference name="content">
15
+ <reference name="contactForm">
16
+ <action method="setTemplate"><template>contactsformcaptcha/form.phtml</template></action>
17
+ </reference>
18
  </reference>
19
+ </contacts_index_index>
20
+ </layout>
app/design/frontend/base/default/template/contactsformcaptcha/form.phtml CHANGED
@@ -24,6 +24,11 @@
24
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
  */
26
  ?>
 
 
 
 
 
27
  <div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
28
  <div class="page-title">
29
  <h1><?php echo Mage::helper('contacts')->__('Contact Us') ?></h1>
@@ -44,26 +49,26 @@
44
  <div class="field">
45
  <label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>
46
  <div class="input-box">
47
- <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
48
  </div>
49
  </div>
50
  <div class="field">
51
  <label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>
52
  <div class="input-box">
53
- <input name="email" id="email" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserEmail()) ?>" class="input-text required-entry validate-email" type="text" />
54
  </div>
55
  </div>
56
  </li>
57
  <li>
58
  <label for="telephone"><?php echo Mage::helper('contacts')->__('Telephone') ?></label>
59
  <div class="input-box">
60
- <input name="telephone" id="telephone" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text" type="text" />
61
  </div>
62
  </li>
63
  <li class="wide">
64
  <label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>
65
  <div class="input-box">
66
- <textarea name="comment" id="comment" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text" cols="5" rows="3"></textarea>
67
  </div>
68
  </li>
69
  <li class="wide">
24
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
  */
26
  ?>
27
+ <?php $contactForm = Mage::getSingleton('core/session')->getData('contactForm'); ?>
28
+ <?php $contactForm = $contactForm ? $contactForm : new Varien_Object(); ?>
29
+ <?php $contactForm->setName( (strlen($contactForm->getName()) > 0 ? $contactForm->getName() : $this->helper('contacts')->getUserName()) ); ?>
30
+ <?php $contactForm->setEmail( (strlen($contactForm->getEmail()) > 0 ? $contactForm->getEmail() : $this->helper('contacts')->getUserEmail()) ); ?>
31
+
32
  <div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
33
  <div class="page-title">
34
  <h1><?php echo Mage::helper('contacts')->__('Contact Us') ?></h1>
49
  <div class="field">
50
  <label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>
51
  <div class="input-box">
52
+ <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->htmlEscape($contactForm->getName()) ?>" class="input-text required-entry" type="text" />
53
  </div>
54
  </div>
55
  <div class="field">
56
  <label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>
57
  <div class="input-box">
58
+ <input name="email" id="email" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->htmlEscape($contactForm->getEmail()) ?>" class="input-text required-entry validate-email" type="text" />
59
  </div>
60
  </div>
61
  </li>
62
  <li>
63
  <label for="telephone"><?php echo Mage::helper('contacts')->__('Telephone') ?></label>
64
  <div class="input-box">
65
+ <input name="telephone" id="telephone" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="<?php echo $this->htmlEscape($contactForm->getTelephone()) ?>" class="input-text" type="text" />
66
  </div>
67
  </li>
68
  <li class="wide">
69
  <label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>
70
  <div class="input-box">
71
+ <textarea name="comment" id="comment" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text" cols="5" rows="3"><?php echo $this->htmlEscape($contactForm->getComment()) ?></textarea>
72
  </div>
73
  </li>
74
  <li class="wide">
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>contactsformcaptcha</name>
4
- <version>1.2.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/OSL-3.0">OSL v3.0</license>
7
  <channel>community</channel>
@@ -10,11 +10,11 @@
10
  <description>"Contacts Form Captcha" extension add in easy way the captcha to "Contact Us" form.&#xD;
11
  &#xD;
12
  This extension uses reCaptcha library (http://www.google.com/recaptcha).</description>
13
- <notes>Added translations of property labels (module configuration page on admin side).</notes>
14
  <authors><author><name>Oleg Koval</name><user>auto-converted</user><email>oleh.koval@gmail.com</email></author></authors>
15
- <date>2013-04-04</date>
16
- <time>08:42:32</time>
17
- <contents><target name="magecommunity"><dir name="OlegKoval"><dir name="ContactsFormCaptcha"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><dir name="Dropdown"><file name="Lang.php" hash="c3b3814ccfc3f97fb8807f0d4ad69d8c"/><file name="Theme.php" hash="c0a7eb1ad6e2157b5f822d0a5d30022c"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="7357f05ccb582bdf53e36a6c0a0f15f7"/></dir><dir name="etc"><file name="config.xml" hash="4e7df714c8fa0c813971c2a4af436845"/><file name="system.xml" hash="53181e763cde62e4d58e21f600abff1a"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="OlegKoval_ContactsFormCaptcha.xml" hash="9b7cbc1587fc43d6a0cd1106bc19a4fc"/></dir></target><target name="magelib"><dir name="reCaptcha"><file name="recaptchalib.php" hash="f80a9f01727de68aba8e98f1e37345a9"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="contactsformcaptcha.xml" hash="797d1d456b4f7e6d4bdbb4308065b5fa"/></dir><dir name="template"><dir name="contactsformcaptcha"><file name="form.phtml" hash="c07fd4475c062ab7e66a54997d72991f"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="OlegKoval_ContactsFormCaptcha.csv" hash="5e430d77c352109bf67305e56b4a3845"/></dir></target></contents>
18
  <compatible/>
19
  <dependencies/>
20
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>contactsformcaptcha</name>
4
+ <version>1.3.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/OSL-3.0">OSL v3.0</license>
7
  <channel>community</channel>
10
  <description>"Contacts Form Captcha" extension add in easy way the captcha to "Contact Us" form.&#xD;
11
  &#xD;
12
  This extension uses reCaptcha library (http://www.google.com/recaptcha).</description>
13
+ <notes>Modified layout logic to show contact form with captcha when use different design themes. Added pre-filling contact form fields by a previous values when customer enter a incorrect captcha code.</notes>
14
  <authors><author><name>Oleg Koval</name><user>auto-converted</user><email>oleh.koval@gmail.com</email></author></authors>
15
+ <date>2013-08-25</date>
16
+ <time>12:52:13</time>
17
+ <contents><target name="magecommunity"><dir name="OlegKoval"><dir name="ContactsFormCaptcha"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><dir name="Dropdown"><file name="Lang.php" hash="c3b3814ccfc3f97fb8807f0d4ad69d8c"/><file name="Theme.php" hash="c0a7eb1ad6e2157b5f822d0a5d30022c"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="a98c088425ea9a0d59f5f04755ee17ca"/></dir><dir name="etc"><file name="config.xml" hash="e66113f7d6509a39cf7d2868b904d352"/><file name="system.xml" hash="53181e763cde62e4d58e21f600abff1a"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="OlegKoval_ContactsFormCaptcha.xml" hash="9b7cbc1587fc43d6a0cd1106bc19a4fc"/></dir></target><target name="magelib"><dir name="reCaptcha"><file name="recaptchalib.php" hash="f80a9f01727de68aba8e98f1e37345a9"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="contactsformcaptcha.xml" hash="c51cd3c07d757ee1985653544fffb2fd"/></dir><dir name="template"><dir name="contactsformcaptcha"><file name="form.phtml" hash="bb89546be7a1730937089f1769438ffc"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="OlegKoval_ContactsFormCaptcha.csv" hash="5e430d77c352109bf67305e56b4a3845"/></dir></target></contents>
18
  <compatible/>
19
  <dependencies/>
20
  </package>