Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
Remove v1 captcha methods. add ability to enable disabled buttons on …
Browse files Browse the repository at this point in the history
…recpatch click
  • Loading branch information
Lucas van Staden committed Nov 23, 2017
1 parent 6efca91 commit 85f741c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 144 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Requirements

Core magento onepage checkout for reCaptcha in Checkout.
There is no plans to extend this extension to ise 3rd party checkouts.
Feel free to extend if you know how. PR welconed.
Feel free to extend if you know how. PRs welcomed.

Installing
==========
Expand Down Expand Up @@ -75,6 +75,23 @@ Setup:
* Obtain your site public key (Site Key) and private key (Secret Key) for your domain and recaptcha usage
* Enter these in the admin settings for captcha.

V1 Captcha support dropped
----------------------------------------------

Since 1.4.0 all v1 captcha (pre I am not a Robot) has been removed. There is thus no longer a theme selection, as only I am not a Robot is supported.

Disable / Enable form submit buttons
------------------------------------

From 1.4.0 you can add teh class 'enable-captcha-clicked' to any element and add the 'disabled' property to that element.
After clicked, the element will be enabled.

example:

```html
<button type="submit" class="btn btn-primary enable-captcha-clicked" disabled="disabled">Submit</button>
```

Making captcha work in magento 1.9 (RWD theme)
----------------------------------------------

Expand Down Expand Up @@ -108,7 +125,7 @@ Contact Us Captcha

<?php echo $this->getChildHtml('recaptcha'); ?>

Unfortunately magento core templates do not accomodate reloading the posted form data.
Unfortunately magento core templates do not accommodate reloading the posted form data.
This means that if the captcha was incorrect, the user will be given a new blank form.
Obviously not ideal.

Expand Down
22 changes: 0 additions & 22 deletions app/code/community/ProxiBlue/ReCaptcha/Model/Config/Themes.php

This file was deleted.

6 changes: 3 additions & 3 deletions app/code/community/ProxiBlue/ReCaptcha/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<ProxiBlue_ReCaptcha>
<version>1.3.0</version>
<version>1.4.0</version>
<depends>
<Mage_Captcha/>
</depends>
Expand Down Expand Up @@ -81,15 +81,15 @@
<admin>
<captcha>
<type>recaptcha</type>
<theme>clean</theme>
<theme>New</theme>
<language>en</language>
<mode>always</mode>
</captcha>
</admin>
<customer>
<captcha>
<type>recaptcha</type>
<theme>clean</theme>
<theme>New</theme>
<language>en</language>
<mode>always</mode>
</captcha>
Expand Down
24 changes: 0 additions & 24 deletions app/code/community/ProxiBlue/ReCaptcha/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@
<type>recaptcha</type>
</depends>
</private_key>
<theme translate="label">
<label>Recaptcha Theme</label>
<frontend_type>select</frontend_type>
<source_model>proxiblue_recaptcha/config_themes</source_model>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends>
<type>recaptcha</type>
</depends>
</theme>
<language translate="label">
<label>Language</label>
<frontend_type>select</frontend_type>
Expand Down Expand Up @@ -132,18 +120,6 @@
<type>recaptcha</type>
</depends>
</private_key>
<theme translate="label">
<label>Recaptcha Theme</label>
<frontend_type>select</frontend_type>
<source_model>proxiblue_recaptcha/config_themes</source_model>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<depends>
<type>recaptcha</type>
</depends>
</theme>
<language translate="label">
<label>Language</label>
<frontend_type>select</frontend_type>
Expand Down
18 changes: 0 additions & 18 deletions app/design/frontend/base/default/layout/proxiblue_recaptcha.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
<action method="setFormId">
<formId>user_contact</formId>
</action>
<action method="setImgWidth">
<width>230</width>
</action>
<action method="setImgHeight">
<width>50</width>
</action>
</block>
</reference>
</contacts_index_index>
Expand All @@ -21,12 +15,6 @@
<action method="setFormId">
<formId>user_review</formId>
</action>
<action method="setImgWidth">
<width>230</width>
</action>
<action method="setImgHeight">
<width>50</width>
</action>
</block>
</reference>
</review_product_list>
Expand All @@ -36,12 +24,6 @@
<action method="setFormId">
<formId>checkout_review</formId>
</action>
<action method="setImgWidth">
<width>230</width>
</action>
<action method="setImgHeight">
<width>50</width>
</action>
</block>
</reference>
</checkout_onepage_review>
Expand Down
104 changes: 29 additions & 75 deletions app/design/frontend/base/default/template/captcha/recaptcha.phtml
Original file line number Diff line number Diff line change
@@ -1,88 +1,42 @@
<?php $captcha = $this->getCaptchaModel() ?>
<?php $theme = $captcha->getTheme(); ?>

<?php if ($theme == 'local'): ?>
<script>
var RecaptchaOptions = {
theme: 'custom',
lang: '<?php echo $captcha->getLanguage(); ?>',
custom_theme_widget: 'recaptcha_widget'
<li id="<?php echo $captcha->getElementId(); ?>">
<div id="<?php echo $captcha->getElementId('image'); ?>" class='proxiblue-recaptcha'></div>
</li>

<?php if ($this->canRenderJS()): ?>
<script type="text/javascript">
var reCaptchaCallback = function () {
window.captchas = [];
$$('.proxiblue-recaptcha').each(
function (elm) {
var cpatchaId = grecaptcha.render(elm.id, {
'sitekey': '<?php echo $captcha->getPublicKey(); ?>',
'callback': function (response) {
// since there are multiple instances of the response text area, populate them all with this response.
// this then will ensure teh correct response is submitted back for this request
$$('.g-recaptcha-response').each(function (elm) {
$(elm).innerText = response;
});
$$('.enable-captcha-clicked').each(function (elm) {
elm.enable();
});
}
});
window.captchas.push(cpatchaId);
}
);
};
</script>
<div id="recaptcha_widget" class="group-select wide fieldset" style="display:none">
<div class="col2-set">
<div class="col-1" style="width: 310px; margin-right: 10px; background: transparent; border: 0px none;">
<div id="recaptcha_image" style="border: 1px solid #CCCCCC; margin-bottom: 10px;"></div>
<div style="text-align: left;">
<span class="recaptcha_only_if_image"><?php echo $this->__(
'Type the image letters or numbers'
); ?></span>
<span class="recaptcha_only_if_audio"><?php echo $this->__('Type what you hear'); ?></span>
<input type="text" id="recaptcha_response_field" name="recaptcha_response_field"
class="input-text required-entry"/>
</div>
</div>
<div class="col-2" style="float: left; width: 25px; background: transparent; border: 0px none;">
<div><a href="javascript:Recaptcha.reload()"><img
src="<?php echo $this->getSkinUrl('recaptcha/images/refresh.png'); ?>"
title="<?php echo $this->__('Load Another Image'); ?>"
alt="<?php echo $this->__('Load Another Image'); ?>"/></a></div>
<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')"><img
src="<?php echo $this->getSkinUrl('recaptcha/images/sound.png'); ?>"
title="<?php echo $this->__('Get an audio challenge'); ?>"
alt="<?php echo $this->__('Get an audio challenge'); ?>"/></a></div>
<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')"><img
src="<?php echo $this->getSkinUrl('recaptcha/images/text.png'); ?>"
title="<?php echo $this->__('Get a visual challenge'); ?>"
alt="<?php echo $this->__('Get a visual challenge'); ?>"/></a></div>
<div><a href="javascript:Recaptcha.showhelp()"><img
src="<?php echo $this->getSkinUrl('fontis/recaptcha/images/help.png'); ?>"
title="<?php echo $this->__('help'); ?>" alt="<?php echo $this->__('help'); ?>"/></a></div>
</div>
</div>

</div>
<?php elseif ($theme == 'New'): ?>
<li id="<?php echo $captcha->getElementId(); ?>">
<div id="<?php echo $captcha->getElementId('image'); ?>" class='proxiblue-recaptcha'></div>
</li>
<?php if ($this->canRenderJS()): ?>
<script type="text/javascript">
var reCaptchaCallback = function () {
window.captchas = [];
$$('.proxiblue-recaptcha').each(
function (elm) {
var cpatchaId = grecaptcha.render(elm.id, {
'sitekey': '<?php echo $captcha->getPublicKey(); ?>',
'callback': function (response) {
// since there are multiple instances of the response text area, populate them all with this response.
// this then will ensure teh correct response is submitted back for this request
$$('.g-recaptcha-response').each(function (elm) {
$(elm).innerText = response;
});
}
});
window.captchas.push(cpatchaId);
}
)
};
</script>
<script
<script
src="https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit&hl=<?php echo $captcha->getLanguage(); ?>"
async
defer></script>
<?php endif; ?>
<?php else: ?>
<script type="text/javascript">
var RecaptchaOptions = {
lang: '<?php echo $captcha->getLanguage(); ?>',
theme: '<?php echo $theme ?>',
};
</script>
<script type="text/javascript" src="<?php echo $captcha->getUrl(); ?>"></script>
<?php endif; ?>
<script>document.observe('billing-request:completed', function (re,result) {
window.captchas.forEach(function(id) {
grecaptcha.reset(id);
});
});</script>
});
</script>

0 comments on commit 85f741c

Please sign in to comment.