• Resolved Lobsterdm

    (@lobsterdm)


    Hi,
    Just wondering if it’s possible to get a Google Recaptcha checkbox to show on the application form? We’re getting some spammy submissions we need to stop.

    Thanks

    The page I need help with: [log in to see the link]

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

    (@braehler)

    @lobsterdm

    although this is not related to the core of WPJM you can do this with this code here.
    Just add this to your functions of your childtheme

    // Define your keys here
    define( 'RECAPTCHA_SITE_KEY', Site Key' );
    define( 'RECAPTCHA_SECRET_KEY', 'Secret Key' );
    // Enqueue Google reCAPTCHA scripts
    add_action( 'wp_enqueue_scripts', 'recaptcha_scripts' );
    function recaptcha_scripts() {
    	wp_enqueue_script( 'recaptcha', 'https://www.google.com/recaptcha/api.js' );
    }
    // Add reCAPTCHA to the job submission form
    // If you disabled company fields, the submit_job_form_end hook can be used instead from version 1.24.1 onwards
    add_action( 'job_application_form_fields_end', 'recaptcha_field' );
    function recaptcha_field() {
    	?>
    	<fieldset>
    		<label>Bitte best?tigen</label>
    		<div class="field">
    			<div class="g-recaptcha" data-sitekey="<?php echo RECAPTCHA_SITE_KEY; ?>"></div>
    		</div>
    	</fieldset>
    	<?php
    }
    // Validate
    add_filter( 'application_form_validate_fields', 'validate_recaptcha_field' );
    function validate_recaptcha_field( $success ) {
    	$response = wp_remote_get( add_query_arg( array(
    		'secret'   => RECAPTCHA_SECRET_KEY,
    		'response' => isset( $_POST['g-recaptcha-response'] ) ? $_POST['g-recaptcha-response'] : '',
    		'remoteip' => isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']
    	), 'https://www.google.com/recaptcha/api/siteverify' ) );
    	if ( is_wp_error( $response ) || empty( $response['body'] ) || ! ( $json = json_decode( $response['body'] ) ) || ! $json->success ) {
    		return new WP_Error( 'validation-error', 'Best?tigung fehlgeschlagen. Bitte versuchen Sie es erneut.' );
    	}
    	return $success;
    }
    Thread Starter Lobsterdm

    (@lobsterdm)

    Hi,
    Thanks for posting this snippet but i can’t seem to get it to work. Keeps giving me the wordpress unavailable error.

    Any ideas?
    Thanks

    @lobsterdm
    for us, this solution works like charm. Maybe your keys are not set up correctly?

    Plugin Support bindlegirl (a11n)

    (@bindlegirl)

    Hi there!

    If you still need help with this, please use this form to get support for our paid add-ons:

    https://wpjobmanager.com/support/

    We are not allowed to support premium plugins in these forums.

    Thanks!

    Thread Starter Lobsterdm

    (@lobsterdm)

    Ah, yes, we had the keys entered wrong in the script. Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WP Job Manager – Applications add on’ is closed to new replies.