Skip to content

Instantly share code, notes, and snippets.

@ThemeCatcher
Last active January 16, 2018 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThemeCatcher/2119445d2115276faa4743201a450fab to your computer and use it in GitHub Desktop.
Save ThemeCatcher/2119445d2115276faa4743201a450fab to your computer and use it in GitHub Desktop.
Save form submissions to the CFDB plugin
<?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