• Resolved webissime

    (@webissime)


    Hello,

    I’d like to know if it’s possible to add hcaptcha to forms?
    Or another plugin that would do this.
    I read there is a captcha inside the html-forms plugins but my customer still receive spam mail.
    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Lap

    (@lapzor)

    I did some testing on how to add a hCaptcha to HTML forms:

    1. Install and activate the hcaptcha plugin, create a free hCaptcha account and add your credentials in the hCaptcha plugin settings
    2. Add the following code snippet to your website:
    add_filter('hf_validate_form', function( $error_code, $form, $data ) {
    $result = hcaptcha_verify_post();
    if ( null !== $result ) {
    $error_code = 'catcha_failed';
    }
    return $error_code;
    },10,3);
    
    add_filter(
    'hf_template_tags',
    function( $tags ) {
    $tags['hcaptcha'] = do_shortcode( '[hcaptcha]' );
    return $tags;
    }
    );
    add_filter( 'hf_validate_form_request_size', false );
    1. add {{hcaptcha}} to your HTML-Forms fields where you want to show the captcha.

    Hope that helps. If you have any questions, please let me know!

    Thread Starter webissime

    (@webissime)

    Man,

    You saved my day.
    I thank you very much.

    goraptors

    (@goraptors)

    @lapzor

    This works brilliantly in php 7.4 but when switching to 8.0 the forms fail to send and I get this message in the PHP error log;

    [17-Oct-2023 12:19:15 UTC] PHP Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, no array or string given in wp-includes/class-wp-hook.php:308

    Do you know how to fix this?

    Thanks

    • This reply was modified 1 year ago by goraptors.
    Lap

    (@lapzor)

    Please change

    add_filter( 'hf_validate_form_request_size', false );

    to

    add_filter( 'hf_validate_form_request_size', '__return_false');

    That should solve that error

    goraptors

    (@goraptors)

    @lapzor Thank you, that solved the issue!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Is it possible to add hCaptcha’ is closed to new replies.