/** * 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; } }
/** * 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')); } }
/** * Create Pod entry from submission * * @since 1.0.0 * * @param array $config Settings for the processor * @param array $form Full form structure * * @return array */ function pods_cf_capture_entry($config, $form) { global $transdata; // get pod ID $pod_id = null; if (!empty($config['pod_id'])) { $pod_id = Caldera_Forms::do_magic_tags($config['pod_id']); } // build entry $entry = array(); // add object fields if (!empty($config['object_fields'])) { foreach ($config['object_fields'] as $object_field => $binding) { if (!empty($binding)) { $entry[$object_field] = Caldera_Forms::get_field_data($binding, $form); } } } $pods = pods($config['pod']); $fields = $pods->fields(); // add pod fields if (!empty($config['fields'])) { foreach ($config['fields'] as $pod_field => $binding) { if (!empty($binding)) { $entry[$pod_field] = Caldera_Forms::get_field_data($binding, $form); } } } // Save Entry if (!empty($pod_id)) { $pod_id = $pods->save($entry, null, $pod_id); } else { $pod_id = $pods->add($entry); } // return entry id for metadata return array('pod_id' => $pod_id, 'permalink' => get_permalink($pod_id)); }
/** * 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; }
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; }
/** * 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; } } } }
/** * Get entries from a form * * @since 1.2.1 * * @param string|array $form Form ID or form config. * @param int $page Optional. Page of entries to get per page. Default is 1. * @param int $perpage Optional. Number of entries per page. Default is 20. * @param string $status Optional. Form status. Default is active. * * @return array */ public static function get_entries($form, $page = 1, $perpage = 20, $status = 'active') { if (is_string($form)) { $form = Caldera_Forms::get_form($form); } 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; if (!empty($field['entry_list'])) { $selects[] = "'" . $field['slug'] . "'"; $field_labels[$field['slug']] = $field['label']; } $has_vars = array(); if (!empty($form['variables']['types'])) { $has_vars = $form['variables']['types']; } if (count($backup_labels) < 4 && !in_array('entryitem', $has_vars) && in_array($field['type'], array('text', 'email', 'date', 'name'))) { // backup only first 4 fields $backup_labels[$field['slug']] = $field['label']; } } } if (empty($field_labels)) { $field_labels = $backup_labels; } //ksort($field_labels); $data = array(); $filter = null; $data['trash'] = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(`id`) AS `total` FROM `" . $wpdb->prefix . "cf_form_entries` WHERE `form_id` = %s AND `status` = 'trash';", $form_id)); $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 if (!empty($status) && isset($data[$status])) { $data['total'] = $data[$status]; } else { $data['total'] = $data['active']; } $data['pages'] = ceil($data['total'] / $perpage); 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['fields'] = $field_labels; $offset = ($page - 1) * $perpage; $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 " . $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['entries'] = 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['entries']['E' . $row->_entryid]['user']['ID'] = $user->ID; $data['entries']['E' . $row->_entryid]['user']['name'] = $user->data->display_name; $data['entries']['E' . $row->_entryid]['user']['email'] = $user->data->user_email; $data['entries']['E' . $row->_entryid]['user']['avatar'] = get_avatar($user->ID, 64); } } $data['entries']['E' . $row->_entryid]['_entry_id'] = $row->_entryid; $data['entries']['E' . $row->_entryid]['_date'] = date_i18n($dateformat . ' ' . $timeformat, get_date_from_gmt($row->_date_submitted, 'U')); // setup default data array if (!isset($data['entries']['E' . $row->_entryid]['data'])) { if (isset($field_labels)) { foreach ($field_labels as $slug => $label) { // setup labels ordering $data['entries']['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['entries']['E' . $row->_entryid]['data'][$row->slug])) { // array based - add another entry if (!is_array($data['entries']['E' . $row->_entryid]['data'][$row->slug])) { $tmp = $data['entries']['E' . $row->_entryid]['data'][$row->slug]; $data['entries']['E' . $row->_entryid]['data'][$row->slug] = array($tmp); } $data['entries']['E' . $row->_entryid]['data'][$row->slug][] = $row->value; } else { $data['entries']['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['fields'][$form['variables']['keys'][$var_key]] = ucwords(str_replace('_', ' ', $form['variables']['keys'][$var_key])); $data['entries']['E' . $row->_entryid]['data'][$form['variables']['keys'][$var_key]] = Caldera_Forms::do_magic_tags($form['variables']['values'][$var_key], $row->_entryid); } } } } } } return $data; }
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);
<?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'];
/** * 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 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; }
/** * Do something to loading of forms * * @since 0.2.0 * * @uses "caldera_forms_ajax_return" * * @param string $out * @param array $form The form configuration * * @return mixed */ function cf_form_connector_control_form_load($out, $form) { if ($out['type'] !== 'complete') { return $out; } if (!empty($form['stage_form'])) { $stage_form = Caldera_Forms::get_form($form['stage_form']); $process_record = cf_form_connector_get_current_position(); if (!empty($form['form_connection'])) { $process_record[$form['stage_form']][$form['ID']] = array('id' => $form['form_connection']['entry_id']); if (empty($form['form_connection']['back_button'])) { $process_record[$form['stage_form']][$form['ID']]['no_back'] = true; } if (!empty($process_record[$form['stage_form']]['previous_form'])) { $process_record[$form['stage_form']][$form['ID']]['back'] = $process_record[$form['stage_form']]['previous_form']; } $process_record[$form['stage_form']]['previous_form'] = $form['ID']; $process_record[$form['stage_form']]['current_form'] = $form['form_connection']['next_form_id']; $process_record[$form['stage_form']]['fields'] = array_merge((array) $process_record[$form['stage_form']]['fields'], $form['fields']); $process_record[$form['stage_form']]['field_values'] = array_merge((array) $process_record[$form['stage_form']]['field_values'], Caldera_Forms::get_submission_data($form)); cf_form_connector_set_current_position($process_record); // handler proper redirects if (!empty($out['url'])) { wp_send_json($out); } wp_send_json(array('target' => $form['stage_form'] . '_' . (int) $_POST['_cf_frm_ct'], 'form' => Caldera_Forms::render_form($stage_form))); } else { // is current = stage ? yup last form last process. if (!empty($process_record[$form['stage_form']]['current_form']) && $process_record[$form['stage_form']]['current_form'] === $form['stage_form']) { $process_record[$form['stage_form']] = array(); cf_form_connector_set_current_position($process_record); return $out; } $process_record[$form['stage_form']][$form['ID']] = array('id' => (int) Caldera_Forms::do_magic_tags('{entry_id}')); if (!empty($process_record[$form['stage_form']]['previous_form'])) { $process_record[$form['stage_form']][$form['ID']]['back'] = $process_record[$form['stage_form']]['previous_form']; } $process_record[$form['stage_form']]['previous_form'] = $form['ID']; $process_record[$form['stage_form']]['current_form'] = $form['stage_form']; $process_record[$form['stage_form']]['fields'] = array_merge((array) $process_record[$form['stage_form']]['fields'], $form['fields']); $process_record[$form['stage_form']]['field_values'] = array_merge((array) $process_record[$form['stage_form']]['field_values'], Caldera_Forms::get_submission_data($form)); cf_form_connector_set_current_position($process_record); Caldera_Forms::process_submission(); exit; } } return $out; }
<?php $polyfill = 'false'; if (!empty($field['config']['pollyfill'])) { $polyfill = 'true'; } if (!empty($field['config']['suffix'])) { $field['config']['suffix'] = Caldera_Forms::do_magic_tags($field['config']['suffix']); } if (!empty($field['config']['prefix'])) { $field['config']['prefix'] = Caldera_Forms::do_magic_tags($field['config']['prefix']); } if (is_array($field_value)) { if (isset($field_value[0])) { $field_value = $field_value[0]; } else { $field_value = 0; } } echo $wrapper_before; ?> <?php echo $field_label; ?> <?php echo $field_before; ?> <div style="position: relative;" <?php if (!empty($field['config']['showval'])) { ?> class="row"<?php
/** * Process entry and save as post/ post meta. * * @since 1.1.0 * * @param array $config Processor config. * @param array $form From config. * * @return array */ function cf_custom_fields_capture_entry($config, $form) { $user_id = get_current_user_id(); if (!empty($config['post_author'])) { $user_id = Caldera_Forms::do_magic_tags($config['post_author']); } $entry = array('post_title' => Caldera_Forms::get_field_data($config['post_title'], $form), 'post_status' => Caldera_Forms::do_magic_tags($config['post_status']), 'post_type' => $config['post_type'], 'post_content' => Caldera_Forms::get_field_data($config['post_content'], $form), 'post_parent' => Caldera_Forms::do_magic_tags($config['post_parent']), 'to_ping' => Caldera_Forms::do_magic_tags($config['to_ping']), 'post_password' => Caldera_Forms::do_magic_tags($config['post_password']), 'post_excerpt' => Caldera_Forms::do_magic_tags($config['post_excerpt']), 'comment_status' => $config['comment_status']); // set the ID if (!empty($config['ID'])) { $is_post_id = Caldera_Forms::do_magic_tags($config['ID']); $post = get_post($is_post_id); if (!empty($post) && $post->post_type == $entry['post_type']) { $entry['ID'] = $is_post_id; } } // set author if (!empty($user_id)) { $entry['post_author'] = $user_id; } //is edit? if (!empty($_POST['_cf_frm_edt'])) { // need to work on this still. SIGH! } else { // Insert the post into the database $entry_id = wp_insert_post($entry); if (empty($entry_id)) { return; } } // do upload + attach if (!empty($config['featured_image'])) { $featured_image = Caldera_Forms::get_field_data($config['featured_image'], $form); foreach ((array) $featured_image as $filename) { $featured_image = cf_custom_fields_attach_file($filename, $entry_id); update_post_meta($entry_id, '_thumbnail_id', $featured_image); } } //get post fields into an array of fields not to save as meta. $post_fields = array_keys($entry); // get all submission data $data = Caldera_Forms::get_submission_data($form); update_post_meta($entry_id, '_cf_form_id', $form['ID']); foreach ($data as $field => $value) { if ('_entry_token' != $field && '_entry_id' != $field) { if (in_array($field, $post_fields) || in_array($form['fields'][$field]['ID'], $post_fields)) { continue; } } if (empty($form['fields'][$field])) { continue; } if (in_array($form['fields'][$field]['type'], array('button', 'html'))) { continue; } if ($form['fields'][$field]['type'] == 'file') { if ($field == $config['featured_image']) { continue; // dont attache twice. } foreach ((array) $value as $file) { cf_custom_fields_attach_file($file, $entry_id); } } update_post_meta($entry_id, $form['fields'][$field]['slug'], $value); } return array('Post ID' => $entry_id, 'ID' => $entry_id, 'permalink' => get_permalink($entry_id)); }
/** * Do something to loading of forms * * @since 0.2.0 * * @uses "caldera_forms_ajax_return" * * @param string $out * @param array $form The form configuration * * @return mixed */ function cf_form_connector_control_form_load($out, $form) { if ($out['type'] !== 'complete') { return $out; } if (!empty($form['stage_form'])) { $stage_form = Caldera_Forms_Forms::get_form($form['stage_form']); $process_record = cf_form_connector_get_current_position(); $process_record[$form['stage_form']]['fields'] = array_merge((array) $process_record[$form['stage_form']]['fields'], $form['fields']); $process_record[$form['stage_form']]['field_values'] = array_merge((array) $process_record[$form['stage_form']]['field_values'], Caldera_Forms::get_submission_data($form)); if (!empty($form['form_connection'])) { $process_record[$form['stage_form']][$form['ID']] = array('id' => $form['form_connection']['entry_id']); if (empty($form['form_connection']['back_button'])) { $process_record[$form['stage_form']][$form['ID']]['no_back'] = true; } if (!empty($process_record[$form['stage_form']]['previous_form'])) { $process_record[$form['stage_form']][$form['ID']]['back'] = $process_record[$form['stage_form']]['previous_form']; } $process_record[$form['stage_form']]['previous_form'] = $form['ID']; $process_record[$form['stage_form']]['current_form'] = $form['form_connection']['next_form_id']; cf_form_connector_set_current_position($process_record); // handler proper redirects if (!empty($out['url'])) { wp_send_json($out); } wp_send_json(array('target' => $form['stage_form'] . '_' . (int) $_POST['_cf_frm_ct'], 'form' => Caldera_Forms::render_form($stage_form))); } else { // is current = stage ? yup last form last process. if (empty($form['form_connection']) || !empty($process_record[$form['stage_form']]['current_form']) && $process_record[$form['stage_form']]['current_form'] === $form['stage_form']) { $connected_form = Caldera_Forms_Forms::get_form($form['stage_form']); if (is_array($connected_form) && (!empty($connected_form['mailer']['enable_mailer']) || $connected_form['mailer']['on_insert'])) { $entry_id = $process_record[$connected_form['ID']]['entry_id']; $data = $process_record[$form['stage_form']]['field_values']; $process_record[$form['stage_form']] = array(); cf_form_connector_set_current_position($process_record); if (class_exists('Caldera_Forms_Magic_Summary')) { $message_setting = $connected_form['mailer']['email_message']; if (false !== strpos($message_setting, '{summary}')) { $magic_parser = new Caldera_Forms_Magic_Summary($connected_form, $data); if (!isset($connected_form['mailer']['email_type']) || $connected_form['mailer']['email_type'] == 'html') { $magic_parser->set_html_mode(true); } else { $magic_parser->set_html_mode(false); } $magic_parser->set_fields(cf_conn_form_get_all_fields($connected_form)); $message_setting = str_replace('{summary}', $magic_parser->get_tag(), $message_setting); $connected_form['mailer']['email_message'] = $message_setting; } } Caldera_Forms_Save_Final::do_mailer($connected_form, $entry_id, $data); } return $out; } $process_record[$form['stage_form']][$form['ID']] = array('id' => (int) Caldera_Forms::do_magic_tags('{entry_id}')); if (!empty($process_record[$form['stage_form']]['previous_form'])) { $process_record[$form['stage_form']][$form['ID']]['back'] = $process_record[$form['stage_form']]['previous_form']; } $process_record[$form['stage_form']]['previous_form'] = $form['ID']; $process_record[$form['stage_form']]['current_form'] = $form['stage_form']; $process_record[$form['stage_form']]['fields'] = array_merge((array) $process_record[$form['stage_form']]['fields'], $form['fields']); $process_record[$form['stage_form']]['field_values'] = array_merge((array) $process_record[$form['stage_form']]['field_values'], Caldera_Forms::get_submission_data($form)); cf_form_connector_set_current_position($process_record); Caldera_Forms::process_submission(); exit; } } return $out; }
/** * 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; } } } }
/** * 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']); } } } }
/** * 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); } } }
template = template.replace( new RegExp("\{\{" + list[i] + "\}\}","g"), value.join(', ') ); } target.html(template).trigger('change'); } $('body').on('change keyup', '<?php echo implode(',', $binds); ?> ', htmltemplate<?php echo $field_id; ?> ); htmltemplate<?php echo $field_id; ?> (); }) </script> <?php $script_template = ob_get_clean(); if (!empty($form['grid_object']) && is_object($form['grid_object'])) { $form['grid_object']->append($script_template, $field['grid_location']); } else { echo $script_template; } } else { echo '<div class="' . $field['config']['custom_class'] . '">' . do_shortcode(Caldera_Forms::do_magic_tags($field['config']['default'])) . '</div>'; }