• Resolved samuelashbr00k

    (@samuelashbr00k)


    I am trying to use this plugin on a custom form however, when i verify the result of hCaptcha challenge using hcaptcha_verify_post() i am receiving the message: “Bad hCaptcha nonce!”.

    As my custom form is submitted using ajax, i have put this code into a jquery submit form function:

    $result = hcaptcha_request_verify();
    
    if ( 'success' !== $result ) {
        // Block processing of the form.
    }

    I cannot seem to successfully verify the results of the hCaptcha challenge, if anyone could help, that would be great. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor kaggdesign

    (@kaggdesign)

    Apologies. We have changed verification functions in v2.0.0 but forgot to update readme.txt.

    Please read the verification sequence like that:

    $result = hcaptcha_verify_post();
    
    if ( null !== $result ) {
        echo esc_html( $result );
        // Block processing of the form.
    }
    
    
    Plugin Contributor kaggdesign

    (@kaggdesign)

    Here is the code of the test mu-plugin. Pus this code in the file /wp-content/mu-plugins/hcap-form.php.

    <?php
    /**
     * Must use plugin to show /hcap-form test page.
     *
     * @package hcaptcha
     */
    
    /**
     * Output /hcap-form page.
     *
     * @return void
     */
    function hcap_form_page() {
    	if (
    		! isset( $_SERVER['REQUEST_URI'] ) ||
    		0 !== strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/hcap-form' )
    	) {
    		return;
    	}
    
    	get_header();
    
    	$test_input = filter_input( INPUT_POST, 'test_input', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
    
    	if ( $test_input ) {
    		echo '<p>You have entered: ' . esc_html( $test_input ) . '</p>';
    
    		$result = hcaptcha_verify_post();
    
    		if ( null !== $result ) {
    			echo '<p>' . esc_html( $result ) . '</p>';
    		}
    	}
    
    	?>
    	<form method="post">
    		<label>
    			<input type="text" name="test_input">
    		</label>
    		<input type="submit" value="Send">
    		<?php echo do_shortcode( '[hcaptcha]' ); ?>
    	</form>
    	<?php
    
    	get_footer();
    	exit();
    }
    
    add_action( 'init', 'hcap_form_page' );
    

    Go to the URL /hcap-form. Ensure that form works and hCaptcha is verified.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Arbitrary form – Bad hCaptcha nonce!’ is closed to new replies.