CFDBIntegrationQuform

"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).

/CFDBIntegrationQuform.php  
  1. class CFDBIntegrationQuform { 
  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://support.themecatcher.net/quform-wordpress/guides/hooks/iphorm_post_process 
  16. add_action('iphorm_post_process', array(&$this, 'saveFormData'), 10, 1); 
  17.  
  18. /** 
  19. * @param $form iPhorm 
  20. * @return bool 
  21. */ 
  22. public function saveFormData($form) { 
  23. try { 
  24. $data = $this->convertData($form); 
  25. return $this->plugin->saveFormData($data); 
  26. } catch (Exception $ex) { 
  27. $this->plugin->getErrorLog()->logException($ex); 
  28. return true; 
  29.  
  30.  
  31. /** 
  32. * @param $form iPhorm 
  33. * @return object 
  34. */ 
  35. public function convertData($form) { 
  36. // http://support.themecatcher.net/quform-wordpress/guides/basic/getting-form-values 
  37. $allValues = $form->getValues(); 
  38.  
  39. // $this->plugin->getErrorLog()->log( 
  40. // print_r($form, true)); 
  41.  
  42. if (is_array($allValues)) { 
  43.  
  44. $postedData = array(); 
  45. $uploadFiles = array(); 
  46.  
  47. foreach ($allValues as $fieldId => $value) { 
  48. // $fieldId is something like "iphorm_2_1" 
  49. // get the human-readable field label 
  50. $fieldName = $fieldId; //iPhorm_Element 
  51. $element = $form->getElement($fieldId); 
  52. if (is_object($element)) { 
  53. $fieldName = $element->getLabel(); 
  54.  
  55. if (is_array($value)) { 
  56. if (array_key_exists('day', $value)) { 
  57. $postedData[$fieldName] = sprintf('%s-%s-%s', $value['year'], $value['month'], $value['day']); 
  58. } else if (array_key_exists('hour', $value)) { 
  59. $postedData[$fieldName] = sprintf('%s:%s %s', $value['hour'], $value['minute'], $value['ampm']); 
  60. } else if (array_key_exists(0, $value)) { 
  61. if (is_array($value[0])) { 
  62. // file upload 
  63. foreach ($value as $upload) { 
  64. $postedData[$fieldName] = $upload['text']; 
  65. $uploadFiles[$fieldName] = $upload['fullPath']; 
  66. } else { 
  67. $postedData[$fieldName] = implode(', ', array_values($value)); 
  68. } else { 
  69. $postedData[$fieldName] = $value; 
  70.  
  71. return (object)array( 
  72. 'title' => $form->getName(),  
  73. 'posted_data' => $postedData,  
  74. 'uploaded_files' => $uploadFiles); 
  75.  
  76.