Loading


Advertisement:

Author Topic: [SOLVED] How to put recpatcha in comments form??  (Read 2581 times)

recaptcher

  • Newbie
  • *
  • Posts: 11
[SOLVED] How to put recpatcha in comments form??
« on: May 04, 2013, 02:30:15 am »
Hi, I'm new here, so first of all, hello everybody.

I would like to put recaptcha in the comments form, like in the contact form in the item.php file. I tried to copy the code, but is not working, recaptcha is not checked on sending. I'm talking about this code:

Code: [Select]
<?php if( osc_recaptcha_public_key() ) { ?>
                                <script type="text/javascript">
                                    var RecaptchaOptions = {
                                        theme : 'custom',
                                        custom_theme_widget: 'recaptcha_widget'
                                    };
                                </script>
                                <style type="text/css"> div#recaptcha_widget, div#recaptcha_image > img { width:280px; } </style>
                                <div id="recaptcha_widget">
                                    <div id="recaptcha_image"><img /></div>
                                    <span class="recaptcha_only_if_image"><?php _e('Enter the words above','modern'); ?>:</span>
                                    <input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />
                                    <div><a href="javascript:Recaptcha.showhelp()"><?php _e('Help''modern'); ?></a></div>
                                </div>
                                <?php ?>
                                <?php osc_show_recaptcha(); ?>


I searched into the forum but I only found how to deactivate it or something about the contact form, but nothing about comments form.


I'm using the latest version of modern theme and osclass, downloaded few days ago.

Thanks in advance. Regards.
« Last Edit: May 05, 2013, 03:08:12 am by recaptcher »

teseo

  • Hero Member
  • *****
  • Posts: 6071
Re: How to put recpatcha in comments form??
« Reply #1 on: May 04, 2013, 02:53:43 am »
Hi, recaptcher :)

You can't have two elements with the same ID in the same document, i.e:

Code: [Select]
<div id="recaptcha_widget">
                                <div id="recaptcha_image"><img /></div>

I'd start renaming the values of all the id's inside this new block, something like "recaptcha_widget_comment" and so on...

Regards

recaptcher

  • Newbie
  • *
  • Posts: 11
Re: How to put recpatcha in comments form??
« Reply #2 on: May 04, 2013, 03:14:56 am »
Hi, thanks for the answer.

I haven't contact seller form, I removed it from the code, because I don't need it. So the problem is not hte double ids, I think...

teseo

  • Hero Member
  • *****
  • Posts: 6071
Re: How to put recpatcha in comments form??
« Reply #3 on: May 04, 2013, 05:10:19 pm »
I presume you have configured Recaptcha and that was correctly working in the Contact form?

I myself I haven't done it yet, so right now I can't do any tests...

Regards

teseo

  • Hero Member
  • *****
  • Posts: 6071
Re: How to put recpatcha in comments form??
« Reply #4 on: May 04, 2013, 05:45:00 pm »
Well, I needed to set it sooner or later anyway, so...  ;D

This is what it seems to work for me:

Put this block right before the Submit button of Comment Form:

Code: [Select]
                    <?php if( osc_recaptcha_items_enabled() ) {?>
                    <div class="box">
                        <div class="row">
                            <?php osc_show_recaptcha(); ?>
                        </div>
                    </div>
                    <?php }?> 
                <div class="clear"></div>

Regards

recaptcher

  • Newbie
  • *
  • Posts: 11
Re: How to put recpatcha in comments form??
« Reply #5 on: May 04, 2013, 07:27:32 pm »
Hi,

yes, recaptcha was working perfectly on contact form. I copied your code, thanks. It's the same, the box is showed but not working, it lets send the comment without captcha submission.

Thanks again.

teseo

  • Hero Member
  • *****
  • Posts: 6071
Re: How to put recpatcha in comments form??
« Reply #6 on: May 04, 2013, 08:16:37 pm »
Ups, didn't think to check that...  :(

Well, I have been doing some digging and this seems to be a matter that would require major surgery.  ??? There is a specific file to do reCaptcha checking just for the Contact Form:

\oc-includes\osclass\controller\contact.php

This file is invoked in index.php:

Code: [Select]
        case ('contact'):   //contact
                            require_once(osc_lib_path() . 'osclass/controller/contact.php');
                            $do = new CWebContact();
                            $do->doModel();

Sorry, seems that there is no easy way to achieve this. The only way to deal with spam in comments seems to be enabling "A comment is being held for moderation" in Settings / Comments.

Regards

recaptcher

  • Newbie
  • *
  • Posts: 11
Re: How to put recpatcha in comments form??
« Reply #7 on: May 04, 2013, 10:18:35 pm »
It seem I'm going to let only the moderation thing...I hope will be enough.

Thanks for your help, anyway.

Regards.

recaptcher

  • Newbie
  • *
  • Posts: 11
Re: How to put recpatcha in comments form??
« Reply #8 on: May 05, 2013, 03:07:54 am »
Hi, I made it.

We have to change 3 files.

1.- in oc-includes/osclass/controller/item.php we have to add another case, case 6, in line 433, with te message you want to show when the captcha code fails:
Code: [Select]
case 6:  $msg = 'Sorry, wrong captcha code';
                                 osc_add_flash_error_message($msg);
                        break;

2.- in oc-includes/oscalls/itemActions.php, below akismet function, in line 875, we have to add this:
Code: [Select]
if( (osc_recaptcha_private_key() != '') ) {
if( !osc_check_recaptcha() ) {
osc_add_flash_error_message( _m('The Recaptcha code is wrong'));
Session::newInstance()->_setForm('commentAuthorName', $authorName);
Session::newInstance()->_setForm('commentTitle', $title);
Session::newInstance()->_setForm('commentAuthorEmail', $authorEmail);
Session::newInstance()->_setForm('commentBody', $body);
return 6;
                        }
                }
3.- in oc-content/themes/modern/item.php just before send button, add this:
Code: [Select]
<?php if( osc_recaptcha_items_enabled() ) {?>
    <div class="box">
<div class="row">
    <?php osc_show_recaptcha(); ?>
</div>
    </div>
    <?php }?> 
<div class="clear"></div>

And that's all. Thanks to teseo for the attention and info. Regards.

ajolo2ky

  • Newbie
  • *
  • Posts: 8
Re: [SOLVED] How to put recpatcha in comments form??
« Reply #9 on: April 08, 2015, 09:34:30 pm »
With this approach I could only show one recaptcha per page so I ended up putting it in the comment box, for not authenticated users, and allowing only logged-in users to contact sellers directly (this is done via the admin interface)