nf_field_recaptcha_pre_process

Function that actually processes our recaptcha.

Description

nf_field_recaptcha_pre_process( (int) $form_id ); 

Runs on a later priority than the field pre_process function

Parameters (1)

0. $form_id (int)
The form id.

Usage

  1. if ( !function_exists( 'nf_field_recaptcha_pre_process' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/fields/recaptcha.php'; 
  3.  
  4. // The form id. 
  5. $form_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = nf_field_recaptcha_pre_process($form_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/deprecated/includes/fields/recaptcha.php  
  1. function nf_field_recaptcha_pre_process( $form_id ) { 
  2. global $ninja_forms_processing; 
  3.  
  4. if ( empty( $_POST['g-recaptcha-response'] ) ) { 
  5. $ninja_forms_processing->add_error( 'error_recaptcha', __( 'Please complete the captcha field' , 'ninja-forms' ) ); 
  6. }else { 
  7. $settings = get_option( 'ninja_forms_settings' ); 
  8. $url = 'https://www.google.com/recaptcha/api/siteverify?secret='.$settings['recaptcha_secret_key'].'&response='.sanitize_text_field( $_POST['g-recaptcha-response'] ); 
  9. $resp = wp_remote_get( esc_url_raw( $url ) ); 
  10.  
  11. if ( !is_wp_error( $resp ) ) { 
  12. $body = wp_remote_retrieve_body( $resp ); 
  13. $response = json_decode( $body ); 
  14. if ( $response->success===false ) { 
  15. if ( !empty( $response->{'error-codes'} ) && $response->{'error-codes'} != 'missing-input-response' ) { 
  16. $error= __( 'Please make sure you have entered your Site & Secret keys correctly', 'ninja-forms' ); 
  17. }else { 
  18. $error= __( 'Captcha mismatch. Please enter the correct value in captcha field', 'ninja-forms' ); 
  19. $ninja_forms_processing->add_error( 'error_recaptcha', $error );