• Resolved Heiko Mitschke

    (@antares7)


    Hello!

    I would like to use hCaptcha as spam protection for my booking forms. I do create the booking form manually via code in booking-fields.php. Displaying the captcha works:

    <?php echo do_shortcode( '[hcaptcha]' ); ?>

    But bookings can be submitted also without solving the captcha. Do I have to tell events manager, that there is another mandatory field?

    Has anyone a hint for me? 🙂

    Thanks in advance and thank you also for this great plugin!

    Kind regards
    Heiko

Viewing 3 replies - 1 through 3 (of 3 total)
  • Maybe try this?

    <?php echo do_shortcode( '[hcaptcha auto="true"]' ); ?>

    https://ww.wp.xz.cn/plugins/hcaptcha-for-forms-and-more/#how%20to%20automatically%20verify%20an%20arbitrary%20form

    • This reply was modified 2 years, 8 months ago by joneiseman.
    Thread Starter Heiko Mitschke

    (@antares7)

    Thanks for your hint. The result is the same as before. The captcha is not a mandatory field…

    Thread Starter Heiko Mitschke

    (@antares7)

    Here is, how I solved the problem.

    Add hCaptcha to the booking form:

    <?php echo do_shortcode( '[hcaptcha]' ); ?>

    Add validation into function.php:

    function em_validate($result, $EM_Event){ 
    	$captcha_result = null;
    	
    	$captcha_result = hcaptcha_verify_post();
    	
    	if ( null !== $captcha_result ) {
    		$EM_Event->add_error('Bitte löse das Captcha-Rätsel.');
    		$result = false;
    	}
    
    	if (!is_user_logged_in() && $_REQUEST['user_name'] == ''){
    		$EM_Event->add_error('Bitte gib deinen Namen an.');
    		$result = false;
    	}
    		
    	if (!is_user_logged_in() && $_REQUEST['user_email'] == ''){
    		$EM_Event->add_error('Bitte gib deine E-Mailadresse an.');
    		$result = false;
    	}	
    	
    	return $result;	
    }
    add_filter('em_booking_validate','em_validate', 1, 2);

    I hope, this will help others to protect the booking form against spam submissions.

    Have fun!
    Heiko

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘hCaptcha integration’ is closed to new replies.