Field values of form not shown while using Dancer2::Plugin::reCAPTCHA

91 Views Asked by At

In a Perl Dancer2 app I'm trying to use the Dancer2::Plugin::reCAPTCHA. Below some code that shows what I've tried. However no success yet.

The code and forms do work without using reCAPTCHA. I see the content of the fields that are entered on the form. What I do not understand is why I don't get to see any result of Data::Dumper in my access.logs

Can someone tell me what I'm doing wrong?

    use Dancer2::Plugin::reCAPTCHA;
    #
    #
    get '/myform-post' => sub {
        template 'form-post', { recaptcha => recaptcha_display() }, {};
    };
    
    #
    #
    post '/my-post' => sub {
        my %FIELD;
        my @field_names = qw(message g-recaptcha-response);
        foreach my $field_name (@field_names) {
            if ( defined param("$field_name") ) {
                $FIELD{$field_name} = param("$field_name");
            }
        }
        print Dumper \%FIELD;   # < why doesn't this appear in access log?---
        my $response = $FIELD{'g-recaptcha-response'};
    
        my $result = recaptcha_verify($response);
        if ( $result->{success} ) {
            print "you are a human";
            open my $fh, '>', $post_file;
            print $fh $FIELD{'message'};
        }
    
        #  else { print $result->{error_codes}->[0]; }
        else {
            print "pech\n";
            return "This doesn't fly.\n";
    
        }
        redirect '/continue-post';
    };

My form template

    <form method="post" action="/my-post" class="form-signin">
    <h2 class="form-signin-heading">Posting echo?</h2>
    <label class="sr-only">Just say something</label>
    <input type="text" name="message" id="message" class="form-control">
    <p>[% recaptcha %]</p>
    <button class="btn btn-lg btn-primary btn-block" type="submit">Submit</button>
    </form>

In the header of the page I make reference to: <script src="https://www.google.com/recaptcha/api.js" async defer></script>

My config:

    appname: "DJ::CP"
    
    layout: "main"
    
    # logging
    log: "core"
    logger: console
    
    behind_proxy: true
    
    charset: "UTF-8"
    
    template: "template_toolkit"
    engines:
      template:
        template_toolkit:
          start_tag: '[%'
          end_tag:   '%]'
    
    
    session: "YAML"
    
    plugins:
      reCAPTCHA:
        site_key: "yabadabadou"
        secret: "obladi"
        options:
          theme: "light"
          type: "image"
          size: "normal"
0

There are 0 best solutions below