CFDBIntegrationNinjaForms

"Contact Form to Database" Copyright (C) 2011-2015 Michael Simpson (email : michael.d.simpson@gmail.com).

Defined (1)

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

/CFDBIntegrationNinjaForms.php  
  1. class CFDBIntegrationNinjaForms { 
  2.  
  3. /** 
  4. * @var CF7DBPlugin 
  5. */ 
  6. var $plugin; 
  7.  
  8. /** 
  9. * @param $plugin CF7DBPlugin 
  10. */ 
  11. function __construct($plugin) { 
  12. $this->plugin = $plugin; 
  13.  
  14. public function registerHooks() { 
  15. // http://docs.ninjaforms.com/article/106-ninjaformspostprocess 
  16. add_action('init', array(&$this, 'registerHook2')); 
  17.  
  18. public function registerHook2() { 
  19. add_action('ninja_forms_post_process', array(&$this, 'saveFormData')); 
  20.  
  21. /** 
  22. * @return bool 
  23. */ 
  24. public function saveFormData() { 
  25. try { 
  26. $data = $this->convertData(); 
  27. return $this->plugin->saveFormData($data); 
  28. } catch (Exception $ex) { 
  29. $this->plugin->getErrorLog()->logException($ex); 
  30. return true; 
  31.  
  32. /** 
  33. * @return object 
  34. */ 
  35. public function convertData() { 
  36. /** 
  37. * @global $ninja_forms_processing Ninja_Forms_Processing 
  38. */ 
  39. global $ninja_forms_processing; 
  40. // $this->plugin->getErrorLog()->log( 
  41. // print_r($ninja_forms_processing, true)); // debug 
  42.  
  43. $postedData = array(); 
  44. $uploadFiles = array(); 
  45.  
  46. // Get all the user submitted values 
  47. $submitted_field_ids = array_keys($ninja_forms_processing->get_all_submitted_fields()); 
  48. $all_fields = $ninja_forms_processing->get_all_fields(); 
  49.  
  50. if (is_array($all_fields)) { 
  51. foreach ($all_fields as $field_id => $user_value) { 
  52. if (in_array($field_id, $submitted_field_ids)) { 
  53. if ($ninja_forms_processing->get_field_setting($field_id, 'type') == '_honeypot') { 
  54. continue; 
  55. $field_name = $ninja_forms_processing->get_field_setting($field_id, 'label'); 
  56. if (is_array($user_value)) { 
  57. $postedData[$field_name] = implode(', ', $user_value); 
  58. } else { 
  59. $postedData[$field_name] = $user_value; 
  60.  
  61. $formTitle = 'Ninja Form'; 
  62. if (isset($ninja_forms_processing->data['form']['form_title'])) { 
  63. $formTitle = $ninja_forms_processing->data['form']['form_title']; 
  64.  
  65. return (object)array( 
  66. 'title' => $formTitle,  
  67. 'posted_data' => $postedData,  
  68. 'uploaded_files' => $uploadFiles); 
  69.  
  70.