Captcha in Virtuemart 2 Enquiry Form (Ask a question about this product)

Started by emtemt, January 01, 2014, 16:35:04 PM

Previous topic - Next topic

emtemt

After a long search to the forum how to implement joomla captcha to the virtuemart enquiry form I have found a solution myself and wanted to share with you.
It is tested with virtuemart 2.0.26a and it is based in the tutorial I found here: http://blog.plite.org/neo_one2199/2013/04/03/use-joomla-default-recaptcha-plugin-in-your-component-or-module/

first we have to enable captcha plugin from plugin manager and fill it with public and private key that we could create from: http://www.google.com/recaptcha

If you have made template overrides, you have to put the code in the overrided files inside: your_template_name/com_virtuemart/askquestion

in the file: components/com_virtuemart/views/askquestion/tmpl/form.php
after textarea and before submit button we add the code:
<? // captcha addition
   JPluginHelper::importPlugin('captcha');
   $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onInit','dynamic_recaptcha_1');
?>
   <div id="dynamic_recaptcha_1"></div>
<? // end of captcha addition
?>

in the file:  components/com_virtuemart/views/askquestion/tmpl/mail_confirmed.php
on the top of the page before php tag close we add:
   // captcha addition
   $post = JRequest::get('post');
   JPluginHelper::importPlugin('captcha');
   $dispatcher = JDispatcher::getInstance();
   $res = $dispatcher->trigger('onCheckAnswer',$post['recaptcha_response_field']);
   if(!$res[0]){

   $askquestion_url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&task=askquestion&virtuemart_product_id=' . $this->product->virtuemart_product_id . '&virtuemart_category_id=' . $this->product->virtuemart_category_id . '&tmpl=component', FALSE);
   die(JText::_('COM_VIRTUEMART_WRONG_CAPTCHA').'&nbsp;&nbsp;<a href="'.$askquestion_url.'">'.JText::_('COM_VIRTUEMART_BACK').'</a>');
}
   // end of captcha addition

in the file:  language/en-GB/en-GB.com_virtuemart.ini
we add the two new variables:
COM_VIRTUEMART_WRONG_CAPTCHA="The captcha code is wrong, please try again"
COM_VIRTUEMART_BACK="back"

Good luck :)
Emmanuel

[attachment cleanup by admin]

servlet

Hello
Thank you for sharing

Pleaste tell me. Is this only for ask a question form. I dont need captcha for registration.
Он-лайн магазин за фототапети http://mishelfoster.com

emtemt


servlet

Thank you for quick answer.
I sugest this code to be implemented in VM by default
Он-лайн магазин за фототапети http://mishelfoster.com

K&K media production

Your code is not working. There is no validation before sending the email.

I've adapt your code and integrated into the VirtueMart Core with options for ask question, recommend email and registration form. It is available with vm 2.5.2.

emtemt

hello again,
I have tested with 2.0.26a and it was working just fine. Maybe it has issues with newer versions but 2.0.26a is for sure ok.
That's nice that you have implemented that to 2.5 by default.

Regards

Pejo

Yep, I was looking just for this, because only trough this now spam can go trough, but this captcha is not working on my Vm 2.0.24

@kkmediaproduction is it possible to get some code or solution here that is working with current VM version (or at least previous)?
Really need something to stop spamming trough "ask a question about this product".

It started today and it is really annoying. Other forms (registration, contact, etc) are protected with captcha, so it is OK.

Milbo

just vm2.5.2.

You can directly update. It is the RC of vm2.6. The reason we did not released it yet as vm2.6 is just that we need more tests, in special of the captcha. It is more likely that you are doing an error changing the 5 files than just using the latest version.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

K&K media production

Quote from: emtemt on March 09, 2014, 10:35:15 AM
hello again,
I have tested with 2.0.26a and it was working just fine. Maybe it has issues with newer versions but 2.0.26a is for sure ok.
That's nice that you have implemented that to 2.5 by default.

Regards

Sure? You have no validation before sending the mail. So if you enter a wrong code, the mail is sending and only for the confirming site is a validation check.

jjk

Quote from: Pejo on March 10, 2014, 00:05:54 AM
Really need something to stop spamming trough "ask a question about this product".
It started today and it is really annoying. Other forms (registration, contact, etc) are protected with captcha, so it is OK.

The ReCaptcha is just one option to prevent spam using the VM 'Ask a question' form. Another one is 'EasyCalcCheck Plus', which is available in the Joomla Extension Directory. 'SpambotCheck' works pretty well, too.

However, at present the devs need some feedback about how ReCaptcha works in VM 2.5.2+
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

ptrouw

Quote from: Milbo on March 10, 2014, 10:01:17 AM
just vm2.5.2.

You can directly update. It is the RC of vm2.6. The reason we did not released it yet as vm2.6 is just that we need more tests, in special of the captcha. It is more likely that you are doing an error changing the 5 files than just using the latest version.

Hi,

You mentioned vm2.5.2 has captcha already. I am running 2.0.26d, should I upgrade a production site to vm 2.5.2?
Is this the next official stable release?
Will it be available shortly within the automatic update service?

kigri

Hello,

I followed all the steps. The captcha appears in the form but when I leave it blank or I enter a wrong code, an email is still sending. Why??
Could anyone help???
I am using virtuemart 2.0.10 and I use captcha in registration and contact form correctly.

Thank you in advance,
kigri

GJC Web Design

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

jjk

VirtueMart 2.0.10 was released in 2012. The captcha was implemented in version 2.5.2 in 2014 as stated for example in the post above yours. You should update to one of the latest versions either from here: http://dev.virtuemart.net/projects/virtuemart/files or here: http://virtuemart.net/downloads
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

kigri

Thank you very much for your answers!
I installed 2.6.14 and it works!!!
Thanks!!