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').' <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]
Hello
Thank you for sharing
Pleaste tell me. Is this only for ask a question form. I dont need captcha for registration.
that's right, only for enquiry form not for registration! :)
Thank you for quick answer.
I sugest this code to be implemented in VM by default
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.
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
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.
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.
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.
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+
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?
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
virtuemart 2.0.10 ??? wildly out of date and unsafe
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
Thank you very much for your answers!
I installed 2.6.14 and it works!!!
Thanks!!
Quote from: kigri on February 10, 2015, 18:10:55 PM
I installed 2.6.14 and it works!!!
If you are just starting a new shop, I would rather install VM 3.0.4, even if you still use Joomla 2.5.28 instead for some reason.
Sorry again, but finally, while the capthca is operating correctly, when I press the button, a blank page appears and I do not have any message.
However, the information email arrives normally.
What is going on?
How can I change what appears after I click on the button?
I use Joomla 2.5.7. I don't want to change it because I am scared that my template will not be working propely.
Do you suggest me to install VM 3.0.4 with Joomla 2.5.7?
Thank you!
Joomla 2.5.7 should not be used as it has critical security holes, and sites with versions even later than that one have been hacked. http://forum.virtuemart.net/index.php?topic=118683.0
Any update should always be tested on a backup copy of the live site.