ninja_forms_json_response

The Ninja Forms ninja forms json response function.

Description

ninja_forms_json_response(); 

Usage

  1. if ( !function_exists( 'ninja_forms_json_response' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/database.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = ninja_forms_json_response(); 
  7.  

Defined (1)

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

/deprecated/includes/database.php  
  1. function ninja_forms_json_response() { 
  2. global $ninja_forms_processing; 
  3.  
  4. $form_id = $ninja_forms_processing->get_form_ID(); 
  5.  
  6. $errors = $ninja_forms_processing->get_all_errors(); 
  7. $success = $ninja_forms_processing->get_all_success_msgs(); 
  8. $fields = $ninja_forms_processing->get_all_fields(); 
  9. $form_settings = $ninja_forms_processing->get_all_form_settings(); 
  10. $extras = $ninja_forms_processing->get_all_extras(); 
  11.  
  12. // Success will default to false if there is not success message. 
  13. if ( ! $success && ! $errors ) $success = true; 
  14.  
  15. if( version_compare( phpversion(), '5.3', '>=' ) ) { 
  16. $json = json_encode( array( 'form_id' => $form_id, 'errors' => $errors, 'success' => $success, 'fields' => $fields, 'form_settings' => $form_settings, 'extras' => $extras ), JSON_HEX_QUOT | JSON_HEX_TAG ); 
  17. }else{ 
  18.  
  19.  
  20. $errors = ninja_forms_html_entity_decode_deep( $errors ); 
  21. $success = ninja_forms_html_entity_decode_deep( $success ); 
  22. $fields = ninja_forms_html_entity_decode_deep( $fields ); 
  23. $form_settings = ninja_forms_html_entity_decode_deep( $form_settings ); 
  24. $extras = ninja_forms_html_entity_decode_deep( $extras ); 
  25.  
  26. $errors = utf8_encode_recursive( $errors ); 
  27. $success = utf8_encode_recursive( $success ); 
  28. $fields = utf8_encode_recursive( $fields ); 
  29. $form_settings = utf8_encode_recursive( $form_settings ); 
  30. $extras = utf8_encode_recursive( $extras ); 
  31.  
  32. $errors = ninja_forms_str_replace_deep( '"', "\u0022", $errors ); 
  33. $errors = ninja_forms_str_replace_deep( "'", "\u0027", $errors ); 
  34. $errors = ninja_forms_str_replace_deep( '<', "\u003C", $errors ); 
  35. $errors = ninja_forms_str_replace_deep( '>', "\u003E", $errors ); 
  36.  
  37. $success = ninja_forms_str_replace_deep( '"', "\u0022", $success ); 
  38. $success = ninja_forms_str_replace_deep( "'", "\u0027", $success ); 
  39. $success = ninja_forms_str_replace_deep( '<', "\u003C", $success ); 
  40. $success = ninja_forms_str_replace_deep( '>', "\u003E", $success ); 
  41.  
  42. $fields = ninja_forms_str_replace_deep( '"', "\u0022", $fields ); 
  43. $fields = ninja_forms_str_replace_deep( "'", "\u0027", $fields ); 
  44. $fields = ninja_forms_str_replace_deep( '<', "\u003C", $fields ); 
  45. $fields = ninja_forms_str_replace_deep( '>', "\u003E", $fields ); 
  46.  
  47. $form_settings = ninja_forms_str_replace_deep( '"', "\u0022", $form_settings ); 
  48. $form_settings = ninja_forms_str_replace_deep( "'", "\u0027", $form_settings ); 
  49. $form_settings = ninja_forms_str_replace_deep( '<', "\u003C", $form_settings ); 
  50. $form_settings = ninja_forms_str_replace_deep( '>', "\u003E", $form_settings ); 
  51.  
  52. $extras = ninja_forms_str_replace_deep( '"', "\u0022", $extras ); 
  53. $extras = ninja_forms_str_replace_deep( "'", "\u0027", $extras ); 
  54. $extras = ninja_forms_str_replace_deep( '<', "\u003C", $extras ); 
  55. $extras = ninja_forms_str_replace_deep( '>', "\u003E", $extras ); 
  56.  
  57. $json = json_encode( array( 'form_id' => $form_id, 'errors' => $errors, 'success' => $success, 'fields' => $fields, 'form_settings' => $form_settings, 'extras' => $extras ) ); 
  58. $json = str_replace( "\\\u0022", "\\u0022", $json ); 
  59. $json = str_replace( "\\\u0027", "\\u0027", $json ); 
  60. $json = str_replace( "\\\u003C", "\\u003C", $json ); 
  61. $json = str_replace( "\\\u003E", "\\u003E", $json ); 
  62.  
  63. return $json;