/** * 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; }
/** * Save final form data * * @param array $form Form config * * @return void|\WP_Error */ public static function save_final_form($form) { global $transdata; $entryid = null; // check submit type (new or update) if (isset($_POST['_cf_frm_edt'])) { // is edit //check user can edit this item. $user_id = get_current_user_id(); $details = Caldera_Forms::get_entry_detail($_POST['_cf_frm_edt'], $form); // check token if (isset($_POST['_cf_frm_edt_tkn'])) { // build token $token_array = array('id' => (int) $details['id'], 'datestamp' => $details['datestamp'], 'user_id' => (int) $details['user_id'], 'form_id' => $form['ID']); if (sha1(json_encode($token_array)) !== trim($_POST['_cf_frm_edt_tkn'])) { return new WP_Error('error', __("Permission denied.", "caldera-forms")); } else { $entryid = (int) $details['id']; $edit_token = sha1(json_encode($token_array)); } } else { if (!empty($user_id)) { if (!empty($details)) { // check user can edit if (current_user_can('edit_posts') || $details['user_id'] === $user_id) { $entryid = $_POST['_cf_frm_edt']; } else { return new WP_Error('error', __("Permission denied.", "caldera-forms")); } } } } } // pull in the class include_once CFCORE_PATH . 'classes/save.php'; if (!empty($form['db_support'])) { Caldera_Forms_Save_Final::save_in_db($form, $entryid); } if (!empty($transdata['edit'])) { // update if (empty($form['mailer']['on_update'])) { return; } } else { // insert if (empty($form['mailer']['enable_mailer']) && empty($form['mailer']['on_insert'])) { return; } } Caldera_Forms_Save_Final::do_mailer($form, $entryid); }