function ninja_forms_save_sub() { global $ninja_forms_processing, $ninja_forms_fields; // save forms by default $save = true; // check if there's some legacy save settings saved in the database if (0 === $ninja_forms_processing->get_form_setting('save_subs')) { $save = false; } $save = apply_filters('ninja_forms_save_submission', $save, $ninja_forms_processing->get_form_ID()); if ($save) { $action = $ninja_forms_processing->get_action(); $user_id = $ninja_forms_processing->get_user_ID(); $sub_id = $ninja_forms_processing->get_form_setting('sub_id'); $form_id = $ninja_forms_processing->get_form_ID(); $field_data = $ninja_forms_processing->get_all_fields(); $sub_data = array(); if (is_array($field_data) and !empty($field_data)) { foreach ($field_data as $field_id => $user_value) { $field_row = $ninja_forms_processing->get_field_settings($field_id); $field_type = $field_row['type']; if (isset($ninja_forms_fields[$field_type]['save_sub'])) { $save_sub = $ninja_forms_fields[$field_type]['save_sub']; if ($save_sub) { ninja_forms_remove_from_array($sub_data, "field_id", $field_id, TRUE); $user_value = apply_filters('ninja_forms_save_sub', $user_value, $field_id); if (is_array($user_value)) { $user_value = ninja_forms_esc_html_deep($user_value); } else { $user_value = esc_html($user_value); } array_push($sub_data, array('field_id' => $field_id, 'user_value' => $user_value)); } } } } $args = array('form_id' => $form_id, 'user_id' => $user_id, 'action' => $action, 'data' => serialize($sub_data), 'status' => 1); $args = apply_filters('ninja_forms_save_sub_args', $args); if ($sub_id != '') { $args['sub_id'] = $sub_id; ninja_forms_update_sub($args); do_action('ninja_forms_update_sub', $sub_id); } else { $sub_id = ninja_forms_insert_sub($args); $ninja_forms_processing->update_form_setting('sub_id', $sub_id); do_action('ninja_forms_insert_sub', $sub_id); } } }
function ninja_forms_mp_save_page() { global $ninja_forms_processing, $current_user, $ninja_forms_fields; if ($ninja_forms_processing->get_form_setting('multi_part')) { $form_id = $ninja_forms_processing->get_form_ID(); $pages = $ninja_forms_processing->get_form_setting('mp_pages'); $page_count = count($pages); $ninja_forms_processing->update_extra_value('_page_count', $page_count); $sub_id = $ninja_forms_processing->get_form_setting('sub_id'); $user_id = $ninja_forms_processing->get_user_ID(); $form_id = $ninja_forms_processing->get_form_ID(); $field_data = $ninja_forms_processing->get_all_submitted_fields(); if ($sub_id != '') { $sub_row = ninja_forms_get_sub_by_id($sub_id); $sub_data = $sub_row['data']; $status = $sub_row['status']; } else { $sub_data = array(); $status = 0; } if (is_array($field_data) and !empty($field_data)) { foreach ($field_data as $field_id => $user_value) { array_push($sub_data, array('field_id' => $field_id, 'user_value' => $user_value)); } } foreach ($sub_data as $row) { $ninja_forms_processing->update_field_value($row['field_id'], $row['user_value']); if (!$ninja_forms_processing->get_field_settings($row['field_id'])) { $field_row = ninja_forms_get_field_by_id($row['field_id']); $ninja_forms_processing->update_field_settings($row['field_id'], $field_row); } } $all_fields = $ninja_forms_processing->get_all_fields(); foreach ($all_fields as $field_id => $user_value) { $field = $ninja_forms_processing->get_field_settings($field_id); $field_type = $field['type']; if (isset($ninja_forms_fields[$field_type])) { if ($user_value === false) { if ($user_value === false) { $ninja_forms_processing->update_field_settings($field_id, $field); } } } } ninja_forms_mp_nav_update_current_page(); $current_page = $ninja_forms_processing->get_extra_value('_current_page'); if (function_exists('ninja_forms_conditionals_field_filter')) { ninja_forms_conditionals_field_filter($form_id); foreach ($pages as $page => $vars) { $show = ninja_forms_mp_check_page_conditional($form_id, $page); if (!$show) { ninja_forms_mp_conditional_remove_page($form_id, $page); } } } $field_data = $ninja_forms_processing->get_all_fields(); $sub_data = array(); if (is_array($field_data) and !empty($field_data)) { foreach ($field_data as $field_id => $user_value) { array_push($sub_data, array('field_id' => $field_id, 'user_value' => $user_value)); } } if ($ninja_forms_processing->get_action() == 'submit') { if (isset($_SESSION['ninja_forms_form_' . $form_id . '_form_settings'])) { foreach ($_SESSION['ninja_forms_form_' . $form_id . '_form_settings'] as $setting => $value) { if ($value != '') { $ninja_forms_processing->update_form_setting($setting, $value); } } } ninja_forms_req_fields_process(); unset($_SESSION['ninja_forms_form_' . $form_id . '_form_settings']); } if ($ninja_forms_processing->get_action() == 'mp_save' or $ninja_forms_processing->get_all_errors()) { if (isset($_SESSION['ninja_forms_form_' . $form_id . '_form_settings'])) { foreach ($_SESSION['ninja_forms_form_' . $form_id . '_form_settings'] as $setting => $value) { if ($value != '') { $ninja_forms_processing->update_form_setting($setting, $value); } } } $all_form_settings = $ninja_forms_processing->get_all_form_settings(); $_SESSION['ninja_forms_form_' . $form_id . '_form_settings'] = $all_form_settings; $args = array('form_id' => $form_id, 'user_id' => $user_id, 'status' => $status, 'action' => 'mp_save', 'data' => serialize($sub_data)); if ($sub_id != '') { $args['sub_id'] = $sub_id; ninja_forms_update_sub($args); } else { $sub_id = ninja_forms_insert_sub($args); } $ninja_forms_processing->update_form_setting('sub_id', $sub_id); $ninja_forms_processing->add_error('_mp_save', ''); } } }