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
####
%= form_for surv => (method => 'POST') => begin
%end
####
....
use Mojolicious::Plugin::ReCAPTCHAv2;
sub startup {
....
$self->plugin('ReCAPTCHAv2', {
sitekey => '...',
secret => '....',
});
...
}
####
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->errstr;
$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");
}
}
}
####
my %verify_params = (
remoteip => $c->tx->remote_address,
response => ( $c->req->param('g-recaptcha-response') || '' ),
secret => $plugin->conf->{'secret'},
);
####
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
####
{
hypnotoad => {
listen => ['https://*:3000']
}
}