Beispiel #1
0
/**
 * Proccess submission
 *
 * @since 0.1.0
 *
 * @param array $config Processor config
 * @param array $form Form config
 *
 * @return array
 */
function cf_postmatic_process($config, $form, $transdata)
{
    if (!class_exists('Prompt_Api')) {
        $x = 1;
        return array('type' => 'error', 'note' => __('Postmatic is not active.', 'cf-postmatic'));
    }
    global $cf_postmatic_notice;
    $_message = Caldera_Forms::do_magic_tags($config['success_message']);
    if (!empty($_message)) {
        $message = $_message;
    } else {
        $message = __('Please check your email to confirm subscription.', 'cf-postmatic');
    }
    $subscriber_data = array('email_address' => Caldera_Forms::do_magic_tags($config['email_address']), 'first_name' => Caldera_Forms::do_magic_tags($config['first_name']), 'last_name' => Caldera_Forms::do_magic_tags($config['last_name']));
    $status = Prompt_Api::subscribe($subscriber_data);
    switch ($status) {
        case Prompt_Api::INVALID_EMAIL:
            return array('type' => 'error', 'note' => __("Invalid email address.", 'cf-postmatic'));
            break;
        case Prompt_Api::ALREADY_SUBSCRIBED:
            return array('type' => 'error', 'note' => __("This email address is already subscribed.", 'cf-postmatic'));
            break;
        case Prompt_Api::CONFIRMATION_SENT:
            $cf_postmatic_notice = array('type' => 'success', 'note' => $message);
            break;
        case Prompt_Api::OPT_IN_SENT:
            $cf_postmatic_notice = array('type' => 'success', 'note' => $message);
            break;
    }
}
/**
 * Get Caldera Forms
 *
 * Includes backwards compat for pre-Caldera Forms 1.3.4
 *
 * @since 2.0.5
 *
 * @param string $id_name ID or name of form
 *
 * @return array|void
 */
function cf_custom_fields_get_form($id_name)
{
    if (class_exists('Caldera_Forms_Forms')) {
        $form = Caldera_Forms_Forms::get_form($id_name);
    } else {
        $form = Caldera_Forms::get_form($id_name);
    }
    if (isset($form['ID']) && !isset($form['id'])) {
        $form['id'] = $form['ID'];
    }
    return $form;
}
Beispiel #3
0
 /**
  * Widget output
  *
  * @since unknown
  *
  * @param array $args
  * @param array $instance
  */
 function widget($args, $instance)
 {
     if (!empty($instance['form'])) {
         extract($args, EXTR_SKIP);
         echo $before_widget;
         $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
         if (!empty($title)) {
             echo $before_title . $title . $after_title;
         }
         echo Caldera_Forms::render_form($instance['form']);
         echo $after_widget;
     }
 }
Beispiel #4
0
/**
 *  Process edd-licensed-downloads processor to validate setup
 *
 * @since 0.1.0
 *
 * @param array $config Processor config
 * @param array $form Form config
 *
 * @return array|void
 */
function cf_edd_validate($config, $form)
{
    $value = Caldera_Forms::get_field_data($config['edd_licensed_downloads'], $form);
    // direct field bind can get data, magic tags wont work.
    $_user = Caldera_Forms::do_magic_tags($config['edd_licensed_downloads_user']);
    if (0 < absint($_user)) {
        $user = $_user;
    } else {
        $user = null;
    }
    $downloads = cf_edd_get_downloads_by_licensed_user($user);
    if (!in_array($value, array_keys($downloads))) {
        return array('type' => 'error', 'note' => __("Selected User Does Note Have A License For This Download.", 'cf-edd'));
    }
}
 /**
  * @param $form array
  * @param int $entry_id
  * @return null|object
  */
 public function convertData($form, $entry_id)
 {
     if (is_array($form)) {
         $title = $form['name'];
         $postedData = array();
         $uploadedFiles = array();
         $fields = $form['fields'];
         foreach ($fields as $field_id => $field) {
             $field_value = Caldera_Forms::get_field_data($field_id, $form, $entry_id);
             //                $this->plugin->getErrorLog()->log("$field_id=" . print_r($field_value, true));  // debug
             //                $this->plugin->getErrorLog()->log("$field_id=" . print_r($field, true));  // debug
             if (!array_key_exists($field_id, $form['fields'])) {
                 // ignore non-field entries _entry_id and _entry_token
                 continue;
             }
             $field_name = $field['label'];
             $is_file = in_array($field['type'], array('file', 'advanced_file'));
             if (is_array($field_value)) {
                 $postedData[$field_name] = implode(',', $field_value);
             } else {
                 if ($is_file && $field_value != null) {
                     // $field_value is a URL to the file like
                     // http://SITE.com/wp-content/uploads/2015/05/my_file.png
                     $postedData[$field_name] = basename($field_value);
                     if (!function_exists('get_home_path')) {
                         include_once ABSPATH . '/wp-admin/includes/file.php';
                     }
                     $path = get_home_path() . $this->getUrlWithoutSchemeHostAndPort($field_value);
                     $uploadedFiles[$field_name] = $path;
                 } else {
                     $postedData[$field_name] = $field_value;
                 }
             }
         }
         return (object) array('title' => $title, 'posted_data' => $postedData, 'uploaded_files' => $uploadedFiles);
     }
     return null;
 }
/**
 * Pre-populate options for bound fields
 *
 * @since 1.0.0
 *
 * @param array $field Field config
 *
 * @return array Field config
 */
function pods_cf_populate_options($field)
{
    global $form;
    $processors = Caldera_Forms::get_processor_by_type('pods', $form);
    if (empty($processors)) {
        return $field;
    }
    foreach ($processors as $processor) {
        // is configured
        $fields = array();
        if (!empty($processor['config']['fields'])) {
            $fields = array_merge($fields, $processor['config']['fields']);
        }
        if (!empty($processor['config']['object_fields'])) {
            $fields = array_merge($fields, $processor['config']['object_fields']);
        }
        if ($bound_field = array_search($field['ID'], $fields)) {
            // now lets see if this is a pick field
            $pod = pods($processor['config']['pod'], null, false);
            $pod_field = $pod->fields($bound_field);
            if (!empty($pod_field['options']['required'])) {
                $field['required'] = 1;
            }
            if ($pod_field['type'] === 'pick') {
                $options = PodsForm::options($pod_field['type'], $pod_field);
                include_once PODS_DIR . 'classes/fields/pick.php';
                $fieldtype = new PodsField_Pick();
                $choices = $fieldtype->data($bound_field, null, $options, $pod);
                $field['config']['option'] = array();
                foreach ($choices as $choice_value => $choice_label) {
                    $field['config']['option'][] = array('value' => $choice_value, 'label' => $choice_label);
                }
            }
        }
    }
    return $field;
}
 function form($instance)
 {
     $instance = wp_parse_args((array) $instance, array('title' => ''));
     $title = strip_tags($instance['title']);
     do_action('caldera_forms_widget_form_start', $instance);
     echo "<p><label for=\" " . $this->get_field_id('title') . "\">" . __('Title', 'caldera-forms') . ": <input class=\"widefat\" id=\"" . $this->get_field_id('title') . "\" name=\"" . $this->get_field_name('title') . "\" type=\"text\" value=\"" . esc_attr($title) . "\" /></label></p>\r\n";
     // get forms
     $forms = Caldera_Forms::get_forms();
     echo "<p><label for=\" " . $this->get_field_id('title') . "\">" . __('Form', 'caldera-forms') . ": </label><select style=\"width:100%;\" name=\"" . $this->get_field_name('form') . "\">\r\n";
     echo "<option value=\"\"></option>\r\n";
     if (!empty($forms)) {
         foreach ($forms as $formid => $form) {
             $sel = "";
             if (!empty($instance['form'])) {
                 if ($instance['form'] == $formid) {
                     $sel = ' selected="selected"';
                 }
             }
             echo "<option value=\"" . $formid . "\"" . $sel . ">" . $form['name'] . "</option>\r\n";
         }
     }
     echo "</select></p>\r\n";
     do_action('caldera_forms_widget_form_end', $instance, $this);
 }
Beispiel #8
0
/**
 * Get URL for API for processing a form
 *
 * @since 1.3.2
 *
 * @param string $form_id Form ID
 *
 * @return string
 */
function cf_ajax_api_url($form_id)
{
    return Caldera_Forms::get_submit_url($form_id);
}
Beispiel #9
0
 /**
  * Get values from POST data and set in the value property
  *
  * @since 1.3.0
  *
  * @access protected
  *
  * @param $config
  * @param $form
  */
 protected function set_value($config, $form)
 {
     foreach ($this->fields as $field => $args) {
         if (isset($config[$field])) {
             if ($args['magic']) {
                 $value = Caldera_Forms::do_magic_tags($config[$field]);
             } else {
                 $value = $config[$field];
             }
             $field_id_passed = strpos($value, 'fld_');
             if (false !== $field_id_passed) {
                 $value = Caldera_Forms::get_field_data($value, $form);
             }
         } else {
             $value = null;
         }
         if (!empty($value)) {
             $value = call_user_func($args['sanatize'], $value);
         }
         if (!empty($value)) {
             $this->values[$field] = $value;
         } else {
             if ($args['required']) {
                 $this->add_error($args['message']);
             } else {
                 $this->values[$field] = null;
             }
         }
     }
 }
Beispiel #10
0
 public static function create_form()
 {
     parse_str($_POST['data'], $newform);
     // get form templates
     $form_templates = self::internal_form_templates();
     // get form registry
     $forms = Caldera_Forms::get_forms(true);
     if (empty($forms)) {
         $forms = array();
     }
     if (!empty($newform['clone'])) {
         $clone = $newform['clone'];
     }
     // load template if any
     if (!empty($newform['template'])) {
         if (isset($form_templates[$newform['template']]) && !empty($form_templates[$newform['template']]['template'])) {
             $form_template = $form_templates[$newform['template']]['template'];
         }
     }
     $newform = array("ID" => uniqid('CF'), "name" => $newform['name'], "description" => $newform['description'], "success" => __('Form has been successfully submitted. Thank you.', 'caldera-forms'), "form_ajax" => 1, "hide_form" => 1);
     // is template?
     if (!empty($form_template) && is_array($form_template)) {
         $newform = array_merge($form_template, $newform);
     }
     // add from to list
     $newform = apply_filters('caldera_forms_create_form', $newform);
     $forms[$newform['ID']] = $newform;
     update_option('_caldera_forms', $forms);
     if (!empty($clone)) {
         $clone_form = get_option($clone);
         if (!empty($clone_form['ID']) && $clone == $clone_form['ID']) {
             $newform = array_merge($clone_form, $newform);
         }
     }
     // add form to db
     update_option($newform['ID'], $newform);
     do_action('caldera_forms_create_form', $newform);
     echo $newform['ID'];
     exit;
 }
Beispiel #11
0
    if (!empty($hastags[1])) {
        $binds = array();
        foreach ($hastags[1] as $tag_key => $tag) {
            foreach ($form['fields'] as $key_id => $fcfg) {
                if ($fcfg['slug'] === $tag) {
                    $binds[] = '[data-field="' . $key_id . '"]';
                    $bindfields[] = '"' . $key_id . '_' . $current_form_count . '"';
                    $formula = str_replace($hastags[0][$tag_key], $key_id, $formula);
                }
            }
        }
    }
    // fix POW
    $formula = str_replace('pow(', 'Math.pow(', $formula);
}
$formula = str_replace("\r", '', str_replace("\n", '', str_replace(' ', '', trim(Caldera_Forms::do_magic_tags($formula)))));
$binds = array();
$binds_wrap = array();
$binds_vars = array();
foreach ($form['fields'] as $fid => $cfg) {
    if (false !== strpos($formula, $fid)) {
        //dump($cfg,0);
        $formula = str_replace($fid, $fid, $formula);
        $binds_vars[] = $fid . " = parseFloat( \$('[data-field=\"" . $fid . "\"]').is(':checkbox') ? checked_total_" . $field_base_id . "(\$('[data-field=\"" . $fid . "\"]:checked')) : \$('[data-field=\"" . $fid . "\"]').is(':radio') ? \$('[data-field=\"" . $fid . "\"]:checked').val() : \$('[data-field=\"" . $fid . "\"]').val() ) || 0 ";
        $binds[] = "[data-field=\"" . $fid . "\"]";
        // include a conditional wrapper
        $binds_wrap[] = "#conditional_" . $fid;
    }
}
if (!empty($binds)) {
    $bindtriggers = array_merge($binds, $binds_wrap);
Beispiel #12
0
 /**
  * Get all forms running on the site
  *
  * @since 1.0.0
  *
  * @param $form_list
  *
  * @return mixed
  */
 public function get_forms($form_list)
 {
     if (class_exists('Caldera_Forms')) {
         $forms = \Caldera_Forms::get_forms();
         $form_list['caldera'] = array('name' => __('Caldera Forms', 'caldera-forms'), 'forms' => array());
         foreach ($forms as $form) {
             $form_list['caldera']['forms'][$form['ID']] = $form['name'];
         }
     }
     if (class_exists('RGFormsModel')) {
         $forms = \RGFormsModel::get_forms(null, 'title');
         $form_list['gform'] = array('name' => __('Gravity Forms', 'gravityforms'), 'forms' => array());
         foreach ($forms as $form) {
             $form_list['gform']['forms'][$form->id] = $form->title;
         }
     }
     if (class_exists('NF_Forms')) {
         $nforms = new \NF_Forms();
         $nforms = $nforms->get_all();
         $form_list['ninja'] = array('name' => __('Ninja Forms', 'ninja-forms'), 'forms' => array());
         foreach ($nforms as $form) {
             $form_list['ninja']['forms'][$form] = Ninja_Forms()->form($form)->get_setting('form_title');
         }
     }
     if (class_exists('WPCF7_ContactForm')) {
         $cforms = \WPCF7_ContactForm::find(array('posts_per_page' => -1));
         $form_list['cf7'] = array('name' => __('Contact Form 7', 'contact-form-7'), 'forms' => array());
         foreach ($cforms as $form) {
             $form_list['cf7']['forms'][$form->id()] = $form->title();
         }
     }
     if (class_exists('FrmForm')) {
         $fforms = \FrmForm::getAll();
         $form_list['frmid'] = array('name' => __('Formidable', 'formidable'), 'forms' => array());
         foreach ($fforms as $form) {
             if (!empty($form->is_template)) {
                 continue;
             }
             $form_list['frmid']['forms'][$form->id] = $form->name;
         }
     }
     // jetpack
     if (function_exists('grunion_display_form_view')) {
         global $wpdb;
         $shortcodes = $wpdb->get_results("SELECT `post_id` FROM `" . $wpdb->postmeta . "` WHERE `meta_key` = '_g_feedback_shortcode';", ARRAY_A);
         if (!empty($shortcodes)) {
             $form_list['jp'] = array('name' => __('Jetpack Contact Form', 'jetpack'), 'forms' => array());
             foreach ($shortcodes as $post_id) {
                 $form = get_post($post_id['post_id']);
                 $form_list['jp']['forms'][$post_id['post_id']] = $form->post_title;
             }
         }
     }
     return $form_list;
 }
 /**
  * Get values from POST data and set in the value property
  *
  * @since 1.3.0
  *
  * @access protected
  *
  * @param $config
  * @param $form
  */
 protected function set_value($config, $form)
 {
     foreach ($this->fields as $field => $args) {
         if (isset($config[$field])) {
             if ($args['magic']) {
                 $value = Caldera_Forms::do_magic_tags($config[$field]);
             } else {
                 $value = $config[$field];
             }
             $field_id_passed = strpos($value, 'fld_');
             if (false !== $field_id_passed) {
                 $value = Caldera_Forms::get_field_data($value, $form);
             }
         } else {
             $value = null;
         }
         if (!empty($value)) {
             $value = call_user_func($args['sanatize'], $value);
         }
         /**
          * Filter value for field of processor
          *
          * @since 1.3.1
          *
          * @param mixed $value The value of the field.
          * @param string $field The name of the field.
          * @param array $args Config for this field.
          * @param array $config Processor config.
          * @param array $form Form config.
          */
         $value = apply_filters('caldera_forms_processor_value', $value, $field, $args, $config, $form);
         if (!empty($value)) {
             $this->values[$field] = $value;
         } else {
             if ($args['required']) {
                 $this->add_error($args['message']);
             } else {
                 $this->values[$field] = null;
             }
         }
     }
 }
/**
 * Find taxonomy fields and values
 *
 * @since 2.1.0
 * 
 * @param $all_fields
 *
 * @return array
 */
function cf_custom_fields_get_taxonomy_fields($all_fields)
{
    $tax_fields = array();
    foreach ($all_fields as $field => $value) {
        if (false !== strpos($field, 'cf-custom-fields-tax-')) {
            if (!empty($value)) {
                $tax_fields[$field] = array('taxonomy' => str_replace('cf-custom-fields-tax-', '', $field), 'terms' => Caldera_Forms::do_magic_tags($value));
            }
        }
    }
    return $tax_fields;
}
function cf_ajax_redirect($type, $url, $form)
{
    if (empty($form['form_ajax'])) {
        return;
    }
    if (empty($_POST['cfajax'])) {
        return;
    }
    $data = Caldera_Forms::get_submission_data($form);
    // setup notcies
    $urlparts = parse_url($url);
    $query = array();
    if (!empty($urlparts['query'])) {
        parse_str($urlparts['query'], $query);
    }
    $notices = array();
    $note_general_classes = array('alert');
    $note_general_classes = apply_filters('caldera_forms_render_note_general_classes', $note_general_classes, $form);
    // base id
    $form_id = 'caldera_form_1';
    if ($type == 'complete') {
        if (isset($query['cf_su'])) {
            $notices['success']['note'] = $form['success'];
            $form_id = 'caldera_form_' . $query['cf_su'];
        } else {
            $out['url'] = $url;
            $notices['success']['note'] = __('Redirecting', 'caldera-forms');
        }
    } elseif ($type == 'preprocess') {
        if (isset($query['cf_er'])) {
            $data = get_transient($query['cf_er']);
            if (!empty($data['note'])) {
                $notices[$data['type']]['note'] = $data['note'];
            }
        } else {
            $out['url'] = $url;
            $notices['success']['note'] = __('Redirecting', 'caldera-forms');
        }
    } elseif ($type == 'error') {
        $data = get_transient($query['cf_er']);
        if (!empty($data['note'])) {
            $notices['error']['note'] = $data['note'];
        }
    }
    // check for field erors
    if (!empty($data['fields'])) {
        foreach ($form['fields'] as $fieldid => $field) {
            if (isset($data['fields'][$fieldid])) {
                if ($urlparts['path'] == 'api') {
                    $out['fields'][$field['slug']] = $data['fields'][$fieldid];
                } else {
                    $out['fields'][$fieldid] = $data['fields'][$fieldid];
                }
            }
        }
    }
    $notices = apply_filters('caldera_forms_render_notices', $notices, $form);
    $note_classes = array('success' => array_merge($note_general_classes, array('alert-success')), 'error' => array_merge($note_general_classes, array('alert-error')), 'info' => array_merge($note_general_classes, array('alert-info')), 'warning' => array_merge($note_general_classes, array('alert-warning')), 'danger' => array_merge($note_general_classes, array('alert-danger')));
    $note_classes = apply_filters('caldera_forms_render_note_classes', $note_classes, $form);
    $html = '';
    if (!empty($notices)) {
        // do notices
        foreach ($notices as $note_type => $notice) {
            if (!empty($notice['note'])) {
                $result = Caldera_Forms::do_magic_tags($notice['note']);
                $html .= '<div class=" ' . implode(' ', $note_classes[$note_type]) . '">' . $result . '</div>';
            }
        }
    }
    if (!empty($result)) {
        $out['result'] = $result;
    }
    if (!empty($query)) {
        if (!empty($query['cf_su'])) {
            unset($query['cf_su']);
        }
        if (!empty($query['cf_ee'])) {
            $out['entry'] = $query['cf_ee'];
        }
        $out['data'] = $query;
    }
    $out['html'] = $html;
    $out['type'] = isset($data['type']) ? $data['type'] : $type;
    $out['form_id'] = $form['ID'];
    $out['form_name'] = $form['name'];
    $out['status'] = $type;
    $out = apply_filters('caldera_forms_ajax_return', $out, $form);
    wp_send_json($out);
    exit;
}
function pods_populate_edit_data($data, $form)
{
    $processors = Caldera_Forms::get_processor_by_type('pods', $form);
    if (!empty($processors)) {
        foreach ($processors as $processor) {
            if (empty($processor['config']['pod_id'])) {
                continue;
            }
            $pod = pods($processor['config']['pod'], Caldera_Forms::do_magic_tags($processor['config']['pod_id']));
            foreach ($processor['config']['fields'] as $field => $field_id) {
                if (empty($field_id)) {
                    continue;
                }
                $line = $pod->field($field);
                if (is_array($line)) {
                    foreach ($line as $line_item) {
                        if (isset($line_item['ID'])) {
                            $data[$field_id][$line_item['ID']] = $line_item['ID'];
                        } elseif (isset($line_item['id'])) {
                            $data[$field_id][$line_item['id']] = $line_item['id'];
                        } else {
                            $data[$field_id][] = $line_item;
                        }
                    }
                } else {
                    $data[$field_id] = $line;
                }
            }
        }
    }
    return $data;
}
Beispiel #17
0
/**
 * Shortcode callback for cf_view callback
 *
 * @since 0.0.2
 *
 * @param array $atts
 *
 * @return string|void
 */
function cf_view_shortcode($atts)
{
    $atts = shortcode_atts(array('id' => null, 'fields' => array(), 'editor_id' => 0), $atts, 'cf_view');
    if (is_null($atts['id'])) {
        return;
    }
    $maybe_form = Caldera_Forms::get_form($atts['id']);
    if (is_array($maybe_form)) {
        $form_id = $atts['id'];
    } else {
        return;
    }
    if (!empty($atts['fields'])) {
        $fields = explode(',', $atts['fields']);
    } else {
        $fields = $atts['fields'];
    }
    if (0 < absint($atts['editor_id'])) {
        $maybe_post = get_post($atts['editor_id']);
        if (!is_object($maybe_post)) {
            $editor_id = null;
        } else {
            $editor_id = $atts['editor_id'];
        }
    } else {
        $editor_id = null;
    }
    return cf_view($form_id, $fields, $editor_id);
}
<?php

// Connection builder
$forms = \Caldera_Forms::get_forms();
foreach ($forms as $form_id => $form) {
    if (!empty($form['is_connected_form'])) {
        unset($forms[$form_id]);
        continue;
    }
    $forms[$form_id] = \Caldera_Forms::get_form($form_id);
}
if (!empty($element['condition_points']['conditions'])) {
    foreach ($element['condition_points']['conditions'] as $condition_point) {
        if (empty($element['node'][$condition_point['connect']])) {
            // dont output points for nonexistant forms
            continue;
        }
        if ($condition_point['connect'] == $condition_point['parent']) {
            unset($element['node'][$condition_point['connect']]);
            continue;
        }
        ?>

    <span class="condition-point" data-src="<?php 
        echo $condition_point['id'];
        ?>
" data-name="<?php 
        echo $condition_point['name'];
        ?>
" data-from="<?php 
        echo $condition_point['parent'];
 function lsx_is_form_enabled($slug = false)
 {
     if (false == $slug) {
         return false;
     }
     $match = false;
     $forms = get_option('_caldera_forms', false);
     if (false !== $forms) {
         foreach ($forms as $form_id => $form_maybe) {
             if (trim(strtolower($slug)) == strtolower($form_maybe['name'])) {
                 $match = $form_id;
                 break;
             }
         }
     }
     if (false === $match) {
         $is_form = Caldera_Forms::get_form(strtolower($slug));
         if (!empty($is_form)) {
             return strtolower($slug);
         }
     }
     return $match;
 }
Beispiel #20
0
 /**
  * Load a saved entry.
  *
  * @param null|int $entry_id Entry ID
  * @param null|string|array $form Optional. Config array, or ID of form.
  *
  * @return array
  */
 public static function get_entry($entry_id = null, $form = null)
 {
     if (empty($entry_id)) {
         if (!empty($_POST['form'])) {
             $entry_id = $_POST['entry'];
             // get form and check
             $form = Caldera_Forms_Forms::get_form($_POST['form']);
             if (empty($form['ID']) || $form['ID'] != $_POST['form']) {
                 return;
             }
             $fields = array();
             foreach ($form['fields'] as $field_id => $field) {
                 $fields[$field['slug']] = $field;
             }
         }
         if (empty($form)) {
             return array();
         }
     }
     if (empty($form)) {
         return;
     }
     if (is_string($form)) {
         $form_id = $form;
         $form = Caldera_Forms_Forms::get_form($form);
         if (!isset($form['ID']) || $form['ID'] !== $form_id) {
             return new WP_Error('fail', __('Invalid form ID', 'caldera-forms'));
         }
     }
     // get fields
     $field_types = self::get_field_types();
     $entry = self::get_submission_data($form, $entry_id);
     $data = array('data' => array());
     foreach ($entry as $field_id => $field_value) {
         if (!isset($form['fields'][$field_id]) || !isset($field_types[$form['fields'][$field_id]['type']])) {
             continue;
         }
         if (isset($field_types[$form['fields'][$field_id]['type']]['setup']['not_supported'])) {
             if (in_array('entry_list', $field_types[$form['fields'][$field_id]['type']]['setup']['not_supported'])) {
                 continue;
             }
         }
         //not_supported
         $field = $form['fields'][$field_id];
         /**
          * Filter field config.
          *
          * @param array $field The field config.
          * @param array $form The form config.
          */
         $field = apply_filters('caldera_forms_render_get_field', $field, $form);
         /**
          * Filter field config for fields of a given type.
          *
          * Filter name is dynamic, based on field type. For example "caldera_forms_render_get_field_type-hidden" or "caldera_forms_render_get_field_type-radio"
          *
          * @param array $field The field config.
          * @param array $form The form config.
          */
         $field = apply_filters('caldera_forms_render_get_field_type-' . $field['type'], $field, $form);
         /**
          * Filter field config for fields with a given slug
          *
          * Filter name is dynamic, based on field type. For example "caldera_forms_render_get_field_slug-salsa" or "caldera_forms_render_get_field_slug-chips"
          *
          * @param array $field The field config.
          * @param array $form The form config.
          */
         $field = apply_filters('caldera_forms_render_get_field_slug-' . $field['slug'], $field, $form);
         if (is_string($field_value)) {
             // maybe json?
             $is_json = json_decode($field_value, ARRAY_A);
             if (!empty($is_json) && is_array($is_json)) {
                 $field_value = $is_json;
             } else {
                 $field_value = esc_html(stripslashes_deep($field_value));
             }
         }
         // set view
         $field_view = apply_filters('caldera_forms_view_field_' . $field['type'], $field_value, $field, $form);
         // has options?
         if (!empty($field['config']['option'])) {
             $i = 0;
             foreach ($field['config']['option'] as $opt => $option) {
                 if ($option['value'] == $field_view) {
                     $field_view = $option['label'];
                     if (is_array($field_value)) {
                         if (isset($field_value[$opt])) {
                             $field_value = $field_value[$opt];
                         } else {
                             $field_value = '';
                         }
                     }
                     $data['data'][$field_id . '_' . $i] = array('label' => $field['label'], 'view' => $field_view, 'value' => $field_value);
                     $i++;
                 }
             }
         }
         $data['data'][$field_id] = array('label' => $field['label'], 'view' => $field_view, 'value' => $field_value);
     }
     // get meta
     $dateformat = get_option('date_format');
     $timeformat = get_option('time_format');
     $gmt_offset = get_option('gmt_offset');
     $entry_detail = self::get_entry_detail($entry_id, $form);
     $data['date'] = date_i18n($dateformat . ' ' . $timeformat, get_date_from_gmt($entry_detail['datestamp'], 'U'));
     if (!empty($entry_detail['meta'])) {
         $data['meta'] = $entry_detail['meta'];
     }
     if (!empty($entry_detail['user_id'])) {
         $user = get_userdata($entry_detail['user_id']);
         if (!empty($user)) {
             $data['user'] = array('ID' => $user->ID, 'name' => $user->data->display_name, 'email' => $user->data->user_email, 'avatar' => get_avatar($user->ID, 150, 'identicon'));
         }
     } else {
         $avatar_field = null;
         if (!empty($form['avatar_field'])) {
             $avatar_field = self::get_field_data($form['avatar_field'], $form, $entry_id);
         }
         $data['user'] = array('avatar' => get_avatar($avatar_field, 150));
     }
     if (!empty($form['variables']['types'])) {
         foreach ($form['variables']['types'] as $var_key => $var_type) {
             if ($var_type == 'entryitem') {
                 $var_val = Caldera_Forms::do_magic_tags($form['variables']['values'][$var_key], $entry_id);
                 $data['data']['_var_' . $form['variables']['keys'][$var_key]] = array('label' => ucwords(str_replace('_', ' ', $form['variables']['keys'][$var_key])), 'view' => $var_val, 'value' => sanitize_text_field($var_val));
             }
         }
     }
     // allow plugins to alter the profile.
     $data['user'] = apply_filters('caldera_forms_get_entry_user', $data['user'], $entry_id, $form);
     // set the entry status
     $data['status'] = $entry_detail['status'];
     // allow plugins to alter the entry
     $data = apply_filters('caldera_forms_get_entry', $data, $entry_id, $form);
     if (!empty($_POST['form'])) {
         header('Content-Type: application/json');
         echo json_encode($data);
         exit;
     }
     return $data;
 }
/**
 * Proccesss submission
 *
 * @since 0.1.0
 *
 * @param array $config Processor config
 * @param array $form Form config
 *
 * @return array
 */
function cf_form_connector_process($config, $form)
{
    global $form;
    $form['form_connection'] = $config;
    $form['form_connection']['entry_id'] = Caldera_Forms::get_field_data('_entry_id', $form);
}
Beispiel #22
0
/**
 * Send a Slack API request to invite a user
 *
 * @since 1.1.0
 *
 * @param array $config Processor config
 * @param array $form Form config
 *
 * @return array|bool
 */
function cf_slack_send_invite($config, $form)
{
    $request_args = array('email' => Caldera_Forms::do_magic_tags($config['email']), 'first_name' => Caldera_Forms::do_magic_tags($config['first_name']), 'last_name' => Caldera_Forms::do_magic_tags($config['last_name']), 'token' => $config['token'], 'set_active' => 'true', '_attempts' => 1);
    /**
     * Filter request args before inviting a user
     *
     * Runs before error checking
     *
     * @since 1.1.0
     *
     * @param array $request_args Arguments for API request
     * @param array $config Processor config
     * @param array $form Form config
     */
    add_filter('cf_slack_invite_pre_request', $request_args, $config, $form);
    $required_errors = false;
    if (empty($config['team_name'])) {
        $required_errors[] = array('type' => 'error', 'note' => __('No team was set', 'cf-slack'));
    }
    if (empty($config['token'])) {
        $required_errors[] = array('type' => 'error', 'note' => _('A valid API token was not found', 'cf-slack'));
    }
    if (!is_email($request_args['email'])) {
        $required_errors[] = array('type' => 'error', 'note' => __('Email entered is invalid', 'cf-slack'));
    }
    if (is_array($required_errors)) {
        return $required_errors;
    }
    $url = add_query_arg($request_args, 'https://slack.com/api/users.admin.invite');
    $url = add_query_arg('timestamp', cf_slack_get_timestamp(), $url);
    $response = wp_remote_post($url);
    /**
     * Get response from Slack API invite request.
     *
     * Runs after request is sent, but before form processor ends
     *
     * @since 1.1.0
     *
     * @param WP_Error|array $response The response or WP_Error on failure.
     * @param array $request_args Arguments for API request
     * @param array $config Processor config
     * @param array $form Form config
     */
    do_action('cf_slack_invite_request_sent', $response, $request_args, $config, $form);
    if (!is_wp_error($response) && !is_wp_error(wp_remote_retrieve_body($response))) {
        $response = json_decode(wp_remote_retrieve_body($response));
        if (false == $response->ok) {
            return array('type' => 'error', 'note' => $response->error);
        }
    }
}
Beispiel #23
0
<?php

if (!empty($field['config']['email'])) {
    $email = Caldera_Forms::do_magic_tags($field['config']['email']);
    if (!is_email($email)) {
        $email = '';
    }
} else {
    $email = '';
}
echo $wrapper_before;
?>
	<?php 
echo $field_before;
?>
	<div style="text-align:center;" class="live-gravatar">
		<?php 
/*<span style="background: url(<?php echo admin_url('images/spinner.gif'); ?>) no-repeat scroll center center transparent;overflow: hidden;border-radius:<?php echo $field['config']['border_radius']; ?>px; border:<?php echo $field['config']['border_size']; ?>px solid <?php echo $field['config']['border_color']; ?>;display: inline-block;"> */
?>
		<span style="overflow: hidden;border-radius:<?php 
echo $field['config']['border_radius'];
?>
px; border:<?php 
echo $field['config']['border_size'];
?>
px solid <?php 
echo $field['config']['border_color'];
?>
;display: inline-block;">
			<span style="border-radius:<?php 
echo $field['config']['border_radius'];
<div class="caldera-backdrop caldera-forms-insert-modal" style="display: none;"></div>
<div id="calderaf_forms_shortcode_modal" class="caldera-modal-wrap caldera-forms-insert-modal" style="display: none; width: 600px; max-height: 500px; margin-left: -300px;">
	<div class="caldera-modal-title" id="calderaf_forms_shortcode_modalTitle" style="display: block;">
		<a href="#close" class="caldera-modal-closer" data-dismiss="modal" aria-hidden="true" id="calderaf_forms_shortcode_modalCloser">×</a>
		<h3 class="modal-label" id="calderaf_forms_shortcode_modalLable"><?php 
echo __('Insert Caldera Form', 'caldera-forms');
?>
</h3>
	</div>
	<div class="caldera-modal-body none" id="calderaf_forms_shortcode_modalBody">
		<div class="modal-body">
		<?php 
$forms = Caldera_Forms::get_forms();
if (!empty($forms)) {
    foreach ($forms as $form_id => $form) {
        echo '<div class="modal-list-item"><label><input name="insert_form_id" autocomplete="off" class="selected-form-shortcode" value="' . $form_id . '" type="radio">' . $form['name'];
        if (!empty($form['description'])) {
            echo '<span class="description"> ' . $form['description'] . ' </span>';
        }
        echo ' </label></div>';
        //dump($form,0);
    }
} else {
    echo '<p>' . __('You don\'t have any forms to insert.', 'caldera-forms') . '</p>';
}
?>
		</div>
	</div>
	<div class="caldera-modal-footer" id="calderaf_forms_shortcode_modalFooter" style="display: block;">
	<?php 
if (!empty($forms)) {
<script type="text/html" id="bulk-actions-active-tmpl">
	<option selected="selected" value=""><?php 
echo __('Bulk Actions');
?>
</option>
	<option value="export"><?php 
echo __('Export Selected');
?>
</option>
	<?php 
if (current_user_can(Caldera_Forms::get_manage_cap('manage'))) {
    ?>
<option value="trash"><?php 
    echo __('Move to Trash');
    ?>
</option><?php 
}
?>
</script>

<script type="text/html" id="cf-export-template">
		<input type="hidden" name="export-form" value="{{formid}}">
		<input type="hidden" name="cal_del" value="{{nonce}}">

		<div class="caldera-config-group">
			<label><?php 
echo __('Export Type', 'caldera-forms');
?>
</label>
			<div class="caldera-config-field">
				<select class="form-export-type" name="format" style="width: 230px;">
/**
 * Render fields in editor.
 *
 * @since 1.?.?
 *
 * @param object $post Post object.
 * @param array $args Args
 */
function cf_custom_fields_render($post, $args)
{
    if (isset($_GET['cf_su'])) {
        unset($_GET['cf_su']);
    }
    add_filter('caldera_forms_render_pre_get_entry', 'cf_custom_fields_get_meta_data', 10, 2);
    add_filter('caldera_forms_render_form_element', function ($element) {
        return 'div';
    });
    ob_start();
    echo Caldera_Forms::render_form($args['id']);
    $form = str_replace('_cf_verify', 'metabox_cf_verify', ob_get_clean());
    // register this form for processing'
    echo '<input type="hidden" name="cf_metabox_forms[]" value="' . $args['id'] . '">';
    echo $form;
}
Beispiel #27
0
 /**
  * Add support sub menu page
  *
  * @since 1.3.5
  *
  * @uses "admin_menu" hook
  */
 public static function add_menu_page()
 {
     add_submenu_page('caldera-forms', __('Support', 'caldera-forms'), __('Support', 'caldera-forms'), Caldera_Forms::get_manage_cap('admin'), 'caldera-form-support', array(__CLASS__, 'page'));
 }
Beispiel #28
0
 /**
  * Get The entries from a Caldera Form
  *
  * @since 1.0.0
  *
  * @param string $form_id form ID
  * @param int $page. Optional. Page number for results. Default is 1
  * @param int $perpage Optional. Results per page. Default is 1000
  * @param array $get_fields Optional. Array of fields to get. Default is an empty array, which returns all fields.
  *
  * @return array entries returned
  */
 public static function get_cf_entries($form_id, $page = 1, $perpage = 1000, $get_fields = array())
 {
     if (!class_exists('\\Caldera_Forms')) {
         return;
     }
     $form = \Caldera_Forms::get_form($form_id);
     if (isset($form['ID'])) {
         $form_id = $form['ID'];
     } else {
         return;
     }
     global $wpdb;
     $field_labels = array();
     $backup_labels = array();
     $selects = array();
     // get all fieldtype
     $field_types = \Caldera_Forms::get_field_types();
     $fields = array();
     if (!empty($form['fields'])) {
         foreach ($form['fields'] as $fid => $field) {
             $fields[$field['slug']] = $field;
             $selects[] = "'" . $field['slug'] . "'";
             if (empty($get_fields) || in_array($field['ID'], $get_fields)) {
                 $field_labels[$field['slug']] = $field['label'];
             }
             $has_vars = array();
             if (!empty($form['variables']['types'])) {
                 $has_vars = $form['variables']['types'];
             }
         }
     }
     if (empty($field_labels)) {
         $field_labels = $backup_labels;
     }
     $data = array();
     $filter = null;
     $status = 'active';
     $data['active'] = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(`id`) AS `total` FROM `" . $wpdb->prefix . "cf_form_entries` WHERE `form_id` = %s AND `status` = 'active';", $form_id));
     // set current total
     $data['total'] = $data['active'];
     if (!empty($perpage)) {
         $data['pages'] = ceil($data['total'] / $perpage);
     } else {
         $data['pages'] = 1;
     }
     if (!empty($page)) {
         $page = abs($page);
         if ($page > $data['pages']) {
             $page = $data['pages'];
         }
     }
     $data['current_page'] = $page;
     $gmt_offset = get_option('gmt_offset');
     if ($data['total'] > 0) {
         $data['form'] = $form_id;
         $data['label'] = $field_labels;
         $offset = ($page - 1) * $perpage;
         $limit = null;
         if (!empty($perpage)) {
             $limit = "LIMIT " . $offset . ',' . $perpage;
         }
         $rawdata = $wpdb->get_results($wpdb->prepare("\n\t\t\tSELECT\n\t\t\t\t`id`,\n\t\t\t\t`form_id`\n\t\t\tFROM `" . $wpdb->prefix . "cf_form_entries`\n\n\t\t\tWHERE `form_id` = %s AND `status` = %s ORDER BY `datestamp` DESC " . $limit . ";", $form_id, $status));
         if (!empty($rawdata)) {
             $ids = array();
             foreach ($rawdata as $row) {
                 $ids[] = $row->id;
             }
             $rawdata = $wpdb->get_results("\n\t\t\t\tSELECT\n\t\t\t\t\t`entry`.`id` as `_entryid`,\n\t\t\t\t\t`entry`.`form_id` AS `_form_id`,\n\t\t\t\t\t`entry`.`datestamp` AS `_date_submitted`,\n\t\t\t\t\t`entry`.`user_id` AS `_user_id`,\n\t\t\t\t\t`value`.*\n\n\t\t\t\tFROM `" . $wpdb->prefix . "cf_form_entries` AS `entry`\n\t\t\t\tLEFT JOIN `" . $wpdb->prefix . "cf_form_entry_values` AS `value` ON (`entry`.`id` = `value`.`entry_id`)\n\n\t\t\t\tWHERE `entry`.`id` IN (" . implode(',', $ids) . ")\n\t\t\t\t" . $filter . "\n\t\t\t\tORDER BY `entry`.`datestamp` DESC;");
             $data['entry'] = array();
             $dateformat = get_option('date_format');
             $timeformat = get_option('time_format');
             foreach ($rawdata as $row) {
                 if (!empty($row->_user_id)) {
                     $user = get_userdata($row->_user_id);
                     if (!empty($user)) {
                         $data['entry']['E' . $row->_entryid]['user']['ID'] = $user->ID;
                         $data['entry']['E' . $row->_entryid]['user']['name'] = $user->data->display_name;
                         $data['entry']['E' . $row->_entryid]['user']['email'] = $user->data->user_email;
                         $data['entry']['E' . $row->_entryid]['user']['avatar'] = get_avatar($user->ID, 64);
                     }
                 }
                 $data['entry']['E' . $row->_entryid]['_entry_id'] = $row->_entryid;
                 $data['entry']['E' . $row->_entryid]['_date'] = date_i18n($dateformat . ' ' . $timeformat, get_date_from_gmt($row->_date_submitted, 'U'));
                 // setup default data array
                 if (!isset($data['entry']['E' . $row->_entryid]['data'])) {
                     if (isset($field_labels)) {
                         foreach ($field_labels as $slug => $label) {
                             // setup labels ordering
                             $data['entry']['E' . $row->_entryid]['data'][$slug] = null;
                         }
                     }
                 }
                 if (!empty($field_labels[$row->slug])) {
                     $label = $field_labels[$row->slug];
                     // check view handler
                     $field = $fields[$row->slug];
                     // filter the field to get field data
                     $field = apply_filters('caldera_forms_render_get_field', $field, $form);
                     $field = apply_filters('caldera_forms_render_get_field_type-' . $field['type'], $field, $form);
                     $field = apply_filters('caldera_forms_render_get_field_slug-' . $field['slug'], $field, $form);
                     // maybe json?
                     $is_json = json_decode($row->value, ARRAY_A);
                     if (!empty($is_json)) {
                         $row->value = $is_json;
                     }
                     if (is_string($row->value)) {
                         $row->value = esc_html(stripslashes_deep($row->value));
                     } else {
                         $row->value = stripslashes_deep(\Caldera_Forms_Sanitize::sanitize($row->value));
                     }
                     $row->value = apply_filters('caldera_forms_view_field_' . $field['type'], $row->value, $field, $form);
                     if (isset($data['entry']['E' . $row->_entryid]['data'][$row->slug])) {
                         // array based - add another entry
                         if (!is_array($data['entry']['E' . $row->_entryid]['data'][$row->slug])) {
                             $tmp = $data['entry']['E' . $row->_entryid]['data'][$row->slug];
                             $data['entry']['E' . $row->_entryid]['data'][$row->slug] = array($tmp);
                         }
                         $data['entry']['E' . $row->_entryid]['data'][$row->slug][] = $row->value;
                     } else {
                         $data['entry']['E' . $row->_entryid]['data'][$row->slug] = $row->value;
                     }
                 }
                 if (!empty($form['variables']['types'])) {
                     foreach ($form['variables']['types'] as $var_key => $var_type) {
                         if ($var_type == 'entryitem') {
                             $data['label'][$form['variables']['keys'][$var_key]] = ucwords(str_replace('_', ' ', $form['variables']['keys'][$var_key]));
                             $data['entry']['E' . $row->_entryid]['data'][$form['variables']['keys'][$var_key]] = \Caldera_Forms::do_magic_tags($form['variables']['values'][$var_key], $row->_entryid);
                         }
                     }
                 }
             }
         }
     }
     return $data;
 }
Beispiel #29
0
<article>
	<section class="application">
		<div class="container">
			<div class="column">
				<div class="gutter">
					<div class="content">
						<?php 
echo Caldera_Forms::render_form('CF56e4763fa1bdd');
?>
					</div>
				</div>
			</div>
		</div>
	</section>
</article>
Beispiel #30
0
 /**
  * Process mailer
  *
  * @since 1.2.3
  *
  * @param array $form Form config
  * @param int|null $entryid Optional. ID of entry to send. If not provided, will be deteremined based on global $transdata
  * @param array|null $data Optional. Data to use for sending. If not provided, will be retrieved by form ID.
  */
 public static function do_mailer($form, $entryid = null, $data = null)
 {
     global $transdata;
     if (!$data) {
         $data = Caldera_Forms::get_submission_data($form);
     }
     // add entry ID to transient data
     if (!isset($entryid)) {
         $entryid = null;
     }
     $transdata['entry_id'] = $entryid;
     // do mailer!
     $sendername = __('Caldera Forms Notification', 'caldera-forms');
     if (!empty($form['mailer']['sender_name'])) {
         $sendername = $form['mailer']['sender_name'];
         if (false !== strpos($sendername, '%')) {
             $isname = Caldera_Forms::get_slug_data(trim($sendername, '%'), $form);
             if (!empty($isname)) {
                 $sendername = $isname;
             }
         }
     }
     if (empty($form['mailer']['sender_email'])) {
         $sendermail = get_option('admin_email');
     } else {
         $sendermail = $form['mailer']['sender_email'];
         if (false !== strpos($sendermail, '%')) {
             $ismail = Caldera_Forms::get_slug_data(trim($sendermail, '%'), $form);
             if (is_email($ismail)) {
                 $sendermail = $ismail;
             }
         }
     }
     // use summary
     if (empty($form['mailer']['email_message'])) {
         $form['mailer']['email_message'] = "{summary}";
     }
     $mail = array('recipients' => array(), 'subject' => Caldera_Forms::do_magic_tags($form['mailer']['email_subject']), 'message' => stripslashes($form['mailer']['email_message']) . "\r\n", 'headers' => array(Caldera_Forms::do_magic_tags('From: ' . $sendername . ' <' . $sendermail . '>')), 'attachments' => array());
     // if added a bcc
     if (isset($form['mailer']['bcc_to'])) {
         $mail['headers'][] = Caldera_Forms::do_magic_tags('Bcc: ' . $form['mailer']['bcc_to']);
     }
     // if added a replyto
     $reply_to = trim($form['mailer']['reply_to']);
     if (!empty($reply_to)) {
         $mail['headers'][] = Caldera_Forms::do_magic_tags('Reply-To: <' . $reply_to . '>');
     }
     // Filter Mailer first as not to have user input be filtered
     $mail['message'] = Caldera_Forms::do_magic_tags($mail['message']);
     if ($form['mailer']['email_type'] == 'html') {
         $mail['headers'][] = "Content-type: text/html";
         $mail['message'] = wpautop($mail['message']);
     }
     // get tags
     preg_match_all("/%(.+?)%/", $mail['message'], $hastags);
     if (!empty($hastags[1])) {
         foreach ($hastags[1] as $tag_key => $tag) {
             $tagval = Caldera_Forms::get_slug_data($tag, $form);
             if (is_array($tagval)) {
                 $tagval = implode(', ', $tagval);
             }
             $mail['message'] = str_replace($hastags[0][$tag_key], $tagval, $mail['message']);
         }
     }
     //$mail['message']
     // ifs
     preg_match_all("/\\[if (.+?)?\\](?:(.+?)?\\[\\/if\\])?/", $mail['message'], $hasifs);
     if (!empty($hasifs[1])) {
         // process ifs
         foreach ($hasifs[0] as $if_key => $if_tag) {
             $content = explode('[else]', $hasifs[2][$if_key]);
             if (empty($content[1])) {
                 $content[1] = '';
             }
             $vars = shortcode_parse_atts($hasifs[1][$if_key]);
             foreach ($vars as $varkey => $varval) {
                 if (is_string($varkey)) {
                     $var = Caldera_Forms::get_slug_data($varkey, $form);
                     if (in_array($varval, (array) $var)) {
                         // yes show code
                         $mail['message'] = str_replace($hasifs[0][$if_key], $content[0], $mail['message']);
                     } else {
                         // nope- no code
                         $mail['message'] = str_replace($hasifs[0][$if_key], $content[1], $mail['message']);
                     }
                 } else {
                     $var = Caldera_Forms::get_slug_data($varval, $form);
                     if (!empty($var)) {
                         // show code
                         $mail['message'] = str_replace($hasifs[0][$if_key], $content[0], $mail['message']);
                     } else {
                         // no code
                         $mail['message'] = str_replace($hasifs[0][$if_key], $content[1], $mail['message']);
                     }
                 }
             }
         }
     }
     if (!empty($form['mailer']['recipients'])) {
         $mail['recipients'] = explode(',', Caldera_Forms::do_magic_tags($form['mailer']['recipients']));
     } else {
         $mail['recipients'][] = get_option('admin_email');
     }
     $submission = array();
     foreach ($data as $field_id => $row) {
         if ($row === null || !isset($form['fields'][$field_id])) {
             continue;
         }
         $key = $form['fields'][$field_id]['slug'];
         if (is_array($row)) {
             if (!empty($row)) {
                 $keys = array_keys($row);
                 if (is_int($keys[0])) {
                     $row = implode(', ', $row);
                 } else {
                     $tmp = array();
                     foreach ($row as $linekey => $item) {
                         if (is_array($item)) {
                             $item = '( ' . implode(', ', $item) . ' )';
                         }
                         $tmp[] = $linekey . ': ' . $item;
                     }
                     $row = implode(', ', $tmp);
                 }
             } else {
                 $row = null;
             }
         }
         $mail['message'] = str_replace('%' . $key . '%', $row, $mail['message']);
         $mail['subject'] = str_replace('%' . $key . '%', $row, $mail['subject']);
         $submission[] = $row;
         $labels[] = $form['fields'][$field_id]['label'];
     }
     // final magic
     $mail['message'] = Caldera_Forms::do_magic_tags($mail['message']);
     $mail['subject'] = Caldera_Forms::do_magic_tags($mail['subject']);
     // CSV
     if (!empty($form['mailer']['csv_data'])) {
         ob_start();
         $df = fopen("php://output", 'w');
         fputcsv($df, $labels);
         fputcsv($df, $submission);
         fclose($df);
         $csv = ob_get_clean();
         $csvfile = wp_upload_bits(uniqid() . '.csv', null, $csv);
         if (isset($csvfile['file']) && false == $csvfile['error'] && file_exists($csvfile['file'])) {
             $mail['attachments'][] = $csvfile['file'];
         }
     }
     if (empty($mail)) {
         return;
     }
     /**
      * Filter email data before sending
      *
      * @since 1.2.3 in this location.
      * @since unknown in original location (Caldera_Forms::save_final_form)
      *
      * @param array $mail Email data
      * @param array $data Form entry data
      * @param array $form The form config
      */
     $mail = apply_filters('caldera_forms_mailer', $mail, $data, $form);
     $headers = implode("\r\n", $mail['headers']);
     /**
      * Runs before mail is sent, but after data is prepared
      *
      * @since 1.2.3 in this location.
      * @since unknown in original location (Caldera_Forms::save_final_form)
      * 
      * @param array $mail Email data
      * @param array $data Form entry data
      * @param array $form The form config
      */
     do_action('caldera_forms_do_mailer', $mail, $data, $form);
     // force message to string.
     if (is_array($mail['message'])) {
         $mail['message'] = implode("\n", $mail['message']);
     }
     if (!empty($mail)) {
         // is send debug enabled?
         if (!empty($form['debug_mailer'])) {
             add_action('phpmailer_init', array('Caldera_Forms', 'debug_mail_send'), 1000);
         }
         if (wp_mail((array) $mail['recipients'], $mail['subject'], stripslashes($mail['message']), $headers, $mail['attachments'])) {
             // kill attachment.
             if (!empty($csvfile['file'])) {
                 if (file_exists($csvfile['file'])) {
                     unlink($csvfile['file']);
                 }
             }
             /**
              * Fires main mailer completes
              *
              * @since 1.3.1
              *
              * @param array $mail Email data
              * @param array $data Form entry data
              * @param array $form The form config
              */
             do_action('caldera_forms_mailer_complete', $mail, $data, $form);
         } else {
             /**
              * Fires main mailer fails
              *
              * @since 1.2.3
              *
              * @param array $mail Email data
              * @param array $data Form entry data
              * @param array $form The form config
              */
             do_action('caldera_forms_mailer_failed', $mail, $data, $form);
         }
     } else {
         if (!empty($csvfile['file'])) {
             if (file_exists($csvfile['file'])) {
                 unlink($csvfile['file']);
             }
         }
     }
 }