I'm trying to use Mojolicious::Plugin::ReCAPTCHAv2 to fecht data from a form and insert it in database.

I keep having a warning and a failure when I post the data after using reCaptchaV2

Mojo::Transaction::success is DEPRECATED in favor of Mojo::Transaction +::result and Mojo::Transaction::error at C:/strawberry/perl/site/lib/ +Mojolicious/Plugin/ReCAPTCHAv2.pm line 100. Error code : missing-input-response

From the module page, it is suggested that the error would come from a mistake in the template.

My template is:
%= form_for surv => (method => 'POST') => begin <ul class='form-style-1'> <li> %= label_for name => 'Full name:' %= text_field 'firstname', class=> 'field-divided', placeholder=>'Fir +st' %= text_field 'name', class=> 'field-divided', placeholder=>'Last' ..... %= label_for lang2 => 'Skill in a second national language:' %= select_field lang2 => [[Small => 'small'], [Standard => 'standard'] +, [Good => 'good', selected => 'selected']], class => 'field-select' </li> <li> <%= $captcha %> </li> <li> %= input_tag Send => 'Send', type => 'submit' </li> </ul> %end
I call the plugin in my startup sub
.... use Mojolicious::Plugin::ReCAPTCHAv2; sub startup { .... $self->plugin('ReCAPTCHAv2', { sitekey => '...', secret => '....', }); ... }
And I check the captcha response in my controller post action
sub post { my $c = shift; my $app = $c->app; if ( $app->recaptcha_verify ) { my $p = $c->req->body_params->to_hash; #... test for missing data #build sql string and add the data $app->log->debug($sql); my $stm = $app->db1->prepare($sql) or die $app->db1->errst +r; $stm->execute() or die $stm->errstr; $app->stash( msg => "Data well received, thank you" ); } } else { if ( my $err = $app->recaptcha_get_errors ) { foreach my $e ( @{$err} ) { $app->log->debug( "Error code : " . $e ); } } else { $app->log->debug("Surv.pm: could be a bot here"); } } }
What am I missing ?

Beside, I find these capatcha tests annoying... too much clicks.

IMHO the old captcha version with letters was simpler. Is there a Mojolicious plugin for this ? is there another solution to prevent my table from being filled by students testing their programming skills ?

Thanks !

frazap

Edit: from the module code and Google documentation, I should post something with g-recaptcha-response

In the helper recaptcha_verify :
my %verify_params = ( remoteip => $c->tx->remote_address, response => ( $c->req->param('g-recaptcha-response') | +| '' ), secret => $plugin->conf->{'secret'}, );
I don't think I send anything like this...

edit2:

okay...

here is an example with Mojolicious::Lite that gives the same error. To try it you need to set up a kaptcha for your computer on the google site https://developers.google.com/recaptcha/

use Mojolicious::Lite; use DBI; use Mojolicious::Plugin::ReCAPTCHAv2; plugin 'ReCAPTCHAv2' => { sitekey => '... your value received from google', secret => '... idem', api_timeout => 120, }; get '/surv' => sub { my $c = shift; $c->stash( captcha => $c->app->recaptcha_get_html ); }; post '/surv' => sub { my $c = shift; my $app = $c->app; if ( $app->recaptcha_verify ) { $app->log->debug( "Hi there " . $c->param('first name') ); } else { if ( my $err = $app->recaptcha_get_errors ) { foreach my $e ( @{$err} ) { $app->log->debug( "Error code : " . $e ); } } else { $app->log->debug("could be a bot here"); } } }; app->start; __DATA__ @@ surv.html.ep %= form_for surv => (method => 'POST') => begin %= text_field 'first_name' <%= $captcha %> %= submit_button %en

edit3:

Another problem is that I should served the form over https and not http according to the doc on google's site.

That could be a reason why this is not working

I tried this config file
{ hypnotoad => { listen => ['https://*:3000'] } }

Without success


In reply to Mojolicious::Plugin::ReCAPTCHAv2 : missing -input-response by frazap

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.