function cf_form_process_ajax() { // hook into submision //_cf_cr_pst global $post; if (!empty($_POST['_cf_cr_pst'])) { $post = get_post((int) $_POST['_cf_cr_pst']); } if (isset($_POST['_cf_verify']) && isset($_POST['_cf_frm_id'])) { Caldera_Forms::process_submission(); exit; } }
/** * 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; }
public function api_handler() { global $wp_query; // check for API // if this is not a request for json or a singular object then bail if (!isset($wp_query->query_vars['cf_api'])) { return; } // check if form exists $form = Caldera_Forms_Forms::get_form($wp_query->query_vars['cf_api']); $atts = array('id' => $wp_query->query_vars['cf_api'], 'ajax' => true); if (!empty($_REQUEST['cf_instance'])) { $atts['instance'] = $_REQUEST['cf_instance']; } if (!empty($form['ID'])) { if ($form['ID'] === $wp_query->query_vars['cf_api']) { // got it! // need entry? if (!empty($wp_query->query_vars['cf_entry'])) { $atts['entry'] = (int) $wp_query->query_vars['cf_entry']; //$entry = Caldera_Forms::get_entry($wp_query->query_vars['cf_entry'], $form); //wp_send_json( $entry ); } // is a post? if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($_POST['control'])) { $transient_name = sanitize_key($_POST['control']); $transdata = get_transient($transient_name); if (false === $transdata) { $transdata = array(); } if (!empty($_FILES) && !empty($_POST['field'])) { $form = Caldera_Forms_Forms::get_form($wp_query->query_vars['cf_api']); $field = $form['fields'][$_POST['field']]; $data = cf_handle_file_upload(true, $field, $form); if (is_wp_error($data)) { wp_send_json_error($data->get_error_message()); } $transdata[] = $data; //set set_transient($transient_name, $transdata, DAY_IN_SECONDS); // maybe put in some checks on file then can say yea or nei wp_send_json_success(array()); } } $_POST['_wp_http_referer_true'] = 'api'; $_POST['_cf_frm_id'] = $_POST['cfajax'] = $wp_query->query_vars['cf_api']; $submission = Caldera_Forms::process_submission(); wp_send_json($submission); } } } echo self::render_form($atts); exit; }
/** * Process data on post save. * * @since 1.?.? * * @uses "save_post" action */ function cf_custom_fields_save_post() { if (is_admin()) { if (isset($_POST['cf_metabox_forms'])) { foreach ($_POST['cf_metabox_forms'] as $metaForm) { // add filter to get details of entry $_POST['_cf_frm_id'] = $metaForm; add_filter('caldera_forms_get_entry_detail', 'cf_custom_fields_get_post_details', 10, 3); Caldera_Forms::process_submission(); } } } }
/** * 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; }
public function api_handler() { global $wp_query; // check for API // if this is not a request for json or a singular object then bail if (!isset($wp_query->query_vars['cf_api'])) { return; } // check if form exists $form = self::get_form($wp_query->query_vars['cf_api']); if (!empty($form['ID'])) { if ($form['ID'] === $wp_query->query_vars['cf_api']) { // got it! // need entry? if (!empty($wp_query->query_vars['cf_entry'])) { $entry = Caldera_Forms::get_entry($wp_query->query_vars['cf_entry'], $form); wp_send_json($entry); } // is a post? if ($_SERVER['REQUEST_METHOD'] === 'POST') { $_POST['_wp_http_referer_true'] = 'api'; $_POST['_cf_frm_id'] = $_POST['cfajax'] = $wp_query->query_vars['cf_api']; $submission = Caldera_Forms::process_submission(); wp_send_json($submission); } } } $atts = array('id' => $wp_query->query_vars['cf_api'], 'ajax' => true); echo self::render_form($atts); exit; }
public static function cf_init_system() { global $post, $front_templates, $wp_query, $process_id, $form; // check for API if (!empty($wp_query->query_vars['cf_api'])) { // check if form exists $form = self::get_form($wp_query->query_vars['cf_api']); if (!empty($form['ID'])) { if ($form['ID'] === $wp_query->query_vars['cf_api']) { // got it! // need entry? if (!empty($wp_query->query_vars['cf_entry'])) { $entry = Caldera_Forms::get_entry($wp_query->query_vars['cf_entry'], $form); wp_send_json($entry); } // is a post? if ($_SERVER['REQUEST_METHOD'] === 'POST') { $_POST['_wp_http_referer_true'] = 'api'; $_POST['_cf_frm_id'] = $_POST['cfajax'] = $wp_query->query_vars['cf_api']; $submission = Caldera_Forms::process_submission(); } wp_send_json($wp_query); die; } } } if (!empty($_GET['cf_preview'])) { $form = self::get_form($_GET['cf_preview']); $userid = get_current_user_id(); if (!empty($userid)) { if (empty($form['ID']) || $form['ID'] !== $_GET['cf_preview']) { return; } if (empty($post) || $post->post_title !== 'Caldera Forms Preview') { $temp_page = get_page_by_title('Caldera Forms Preview'); if (empty($temp_page)) { // create page $post = array('post_content' => '', 'post_name' => 'caldera_forms_preview', 'post_title' => 'Caldera Forms Preview', 'post_status' => 'draft', 'post_type' => 'page', 'ping_status' => 'closed', 'comment_status' => 'closed'); $page_id = wp_insert_post($post); wp_redirect(trailingslashit(get_home_url()) . '?page_id=' . $page_id . '&preview=true&cf_preview=' . $_GET['cf_preview']); exit; } if ($temp_page->post_status !== 'draft') { wp_update_post(array('ID' => $temp_page->ID, 'post_status' => 'draft')); } wp_redirect(trailingslashit(get_home_url()) . '?page_id=' . $temp_page->ID . '&preview=true&cf_preview=' . $_GET['cf_preview']); exit; } $post->post_title = $form['name']; $post->post_content = '[caldera_form id="' . $_GET['cf_preview'] . '"]'; } } // catch a transient process if (!empty($_GET['cf_tp'])) { // process a transient stored entry $data = get_transient($_GET['cf_tp']); if (!empty($data) && $data['transient'] === $_GET['cf_tp'] && isset($data['data'])) { // create post values $_POST = array_merge($_POST, $data['data']); // set transient id $_POST['_cf_frm_tr'] = $data['transient']; } } // hook into submision if (isset($_POST['_cf_verify']) && isset($_POST['_cf_frm_id'])) { if (wp_verify_nonce($_POST['_cf_verify'], 'caldera_forms_front')) { self::process_submission(); exit; } exit; /// end form and redirect to submit page or result page. } /* just pull them in! if(empty($post)){ if(isset($wp_query->queried_object)){ $post = $wp_query->queried_object; } } if(empty($post)){ //cant find form; return; }*/ // get fields $field_types = self::get_field_types(); foreach ($field_types as $field_type) { //enqueue styles if (!empty($field_type['styles'])) { foreach ($field_type['styles'] as $style) { if (false !== strpos($style, '//')) { wp_enqueue_style('cf-' . sanitize_key(basename($style)), $style, array(), self::VERSION); } else { wp_enqueue_style($style); } } } //enqueue scripts if (!empty($field_type['scripts'])) { // check for jquery deps $depts[] = 'jquery'; foreach ($field_type['scripts'] as $script) { if (false !== strpos($script, '//')) { wp_enqueue_script('cf-' . sanitize_key(basename($script)), $script, $depts, self::VERSION); } else { wp_enqueue_script($script); } } } } // field styles wp_enqueue_style('cf-frontend-field-styles', CFCORE_URL . 'assets/css/fields.min.css', array(), self::VERSION); $style_includes = get_option('_caldera_forms_styleincludes'); $style_includes = apply_filters('caldera_forms_get_style_includes', $style_includes); if (!empty($style_includes['grid'])) { wp_enqueue_style('cf-grid-styles', CFCORE_URL . 'assets/css/caldera-grid.css', array(), self::VERSION); } if (!empty($style_includes['form'])) { wp_enqueue_style('cf-form-styles', CFCORE_URL . 'assets/css/caldera-form.css', array(), self::VERSION); } if (!empty($style_includes['alert'])) { wp_enqueue_style('cf-alert-styles', CFCORE_URL . 'assets/css/caldera-alert.css', array(), self::VERSION); } // } //} // not a post- if (!isset($post->post_content)) { return; } $codes = get_shortcode_regex(); preg_match_all('/' . $codes . '/s', $post->post_content, $found); if (!empty($found[0][0])) { foreach ($found[2] as $index => $code) { if ('caldera_form' === $code) { if (!empty($found[3][$index])) { $atts = shortcode_parse_atts($found[3][$index]); if (isset($atts['id'])) { // has form get stuff for it $form = self::get_form($atts['id']); if (!empty($form)) { // get list of used fields if (empty($form['fields'])) { /// no filds - next form } // has a form - get field type if (!isset($field_types)) { $field_types = self::get_field_types(); } if (!empty($form['fields'])) { foreach ($form['fields'] as $field) { //enqueue styles if (!empty($field_types[$field['type']]['styles'])) { foreach ($field_types[$field['type']]['styles'] as $style) { if (filter_var($style, FILTER_VALIDATE_URL)) { wp_enqueue_style('cf-' . sanitize_key(basename($style)), $style, array(), self::VERSION); } else { wp_enqueue_style($style); } } } //enqueue scripts if (!empty($field_types[$field['type']]['scripts'])) { // check for jquery deps $depts[] = 'jquery'; foreach ($field_types[$field['type']]['scripts'] as $script) { if (filter_var($script, FILTER_VALIDATE_URL)) { wp_enqueue_script('cf-' . sanitize_key(basename($script)), $script, $depts, self::VERSION); } else { wp_enqueue_script($script); } } } } } // if depts been set- scripts are used - //wp_enqueue_script( 'cf-frontend-script-init', CFCORE_URL . 'assets/js/frontend-script-init.min.js', array('jquery'), self::VERSION, true); if (isset($form['settings']['styles']['use_grid'])) { if ($form['settings']['styles']['use_grid'] === 'yes') { wp_enqueue_style('cf-grid-styles', CFCORE_URL . 'assets/css/caldera-grid.css', array(), self::VERSION); } } if (isset($form['settings']['styles']['use_form'])) { if ($form['settings']['styles']['use_form'] === 'yes') { wp_enqueue_style('cf-form-styles', CFCORE_URL . 'assets/css/caldera-form.css', array(), self::VERSION); } } if (isset($form['settings']['styles']['use_alerts'])) { if ($form['settings']['styles']['use_alerts'] === 'yes') { wp_enqueue_style('cf-alert-styles', CFCORE_URL . 'assets/css/caldera-alert.css', array(), self::VERSION); } } } } } } if ($code == 'caldera_form_modal') { //dump($code); wp_enqueue_style('cf-modal-styles', CFCORE_URL . 'assets/css/modals.css', array(), self::VERSION); //caldera_form_modal } } } }
/** * Makes Caldera Forms go in front-end! */ public static function cf_init_system() { global $post, $front_templates, $wp_query, $process_id, $form; // check for API if (!empty($wp_query->query_vars['cf_api'])) { // check if form exists $form = self::get_form($wp_query->query_vars['cf_api']); if (!empty($form['ID'])) { if ($form['ID'] === $wp_query->query_vars['cf_api']) { // got it! // need entry? if (!empty($wp_query->query_vars['cf_entry'])) { $entry = Caldera_Forms::get_entry($wp_query->query_vars['cf_entry'], $form); wp_send_json($entry); } // is a post? if ($_SERVER['REQUEST_METHOD'] === 'POST') { $_POST['_wp_http_referer_true'] = 'api'; $_POST['_cf_frm_id'] = $_POST['cfajax'] = $wp_query->query_vars['cf_api']; $submission = Caldera_Forms::process_submission(); } wp_send_json($wp_query); die; } } } // catch a transient process if (!empty($_GET['cf_tp'])) { // process a transient stored entry $data = get_transient($_GET['cf_tp']); if (!empty($data) && $data['transient'] === $_GET['cf_tp'] && isset($data['data'])) { // create post values $_POST = array_merge($_POST, $data['data']); // set transient id $_POST['_cf_frm_tr'] = $data['transient']; } } // hook into submission if (isset($_POST['_cf_verify']) && isset($_POST['_cf_frm_id'])) { if (wp_verify_nonce($_POST['_cf_verify'], 'caldera_forms_front')) { self::process_submission(); exit; } exit; /// end form and redirect to submit page or result page. } /* just pull them in! if(empty($post)){ if(isset($wp_query->queried_object)){ $post = $wp_query->queried_object; } } if(empty($post)){ //cant find form; return; }*/ }