Last active
January 16, 2018 11:11
-
-
Save ThemeCatcher/2119445d2115276faa4743201a450fab to your computer and use it in GitHub Desktop.
Save form submissions to the CFDB plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: Quform CFDB | |
* Plugin URI: http://www.quform.com | |
* Description: Save form submissions to the CFDB plugin. | |
* Version: 1.0.1 | |
* Author: ThemeCatcher | |
* Author URI: http://www.themecatcher.net | |
*/ | |
add_action('quform_post_process', function (array $result, Quform_Form $form) { | |
if ( ! class_exists('CF7DBPlugin')) { | |
return; | |
} | |
$cfdbPlugin = new CF7DBPlugin(); | |
try { | |
$postedData = array(); | |
$uploadFiles = array(); | |
foreach ($form->getRecursiveIterator() as $element) { | |
if ($element instanceof Quform_Element_Field && $element->config('saveToDatabase') && ! $element->isConditionallyHidden()) { | |
if ($element instanceof Quform_Element_File) { | |
if ( ! $element->isEmpty()) { | |
$uploads = $element->getValue(); | |
$postedData[$element->getAdminLabel()] = $uploads[0]['name']; | |
$uploadFiles[$element->getAdminLabel()] = $uploads[0]['path']; | |
} | |
} else { | |
$postedData[$element->getAdminLabel()] = $element->getValueText(); | |
} | |
} | |
} | |
$data = (object) array( | |
'title' => $form->config('name'), | |
'posted_data' => $postedData, | |
'uploaded_files' => $uploadFiles | |
); | |
$cfdbPlugin->saveFormData($data); | |
} catch (Exception $ex) { | |
$cfdbPlugin->getErrorLog()->logException($ex); | |
} | |
return $result; | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment