Ejemplo n.º 1
0
function nf_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();
        // If we don't have a submission ID already, create a submission post.
        if (empty($sub_id)) {
            $sub_id = Ninja_Forms()->subs()->create($form_id);
            Ninja_Forms()->sub($sub_id)->update_user_id($user_id);
            do_action('nf_create_sub', $sub_id);
            // Update our legacy $ninja_forms_processing with the new sub_id
            $ninja_forms_processing->update_form_setting('sub_id', $sub_id);
        }
        do_action('nf_before_save_sub', $sub_id);
        Ninja_Forms()->sub($sub_id)->update_action($action);
        if (is_array($field_data) && !empty($field_data)) {
            // Loop through our submitted data and add the values found there.
            // Maintain backwards compatibility with older extensions that use the ninja_forms_save_sub_args filter.
            $data = array();
            //
            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) {
                        $user_value = apply_filters('nf_save_sub_user_value', $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);
                        }
                        // Add our submitted field value.
                        Ninja_Forms()->sub($sub_id)->add_field($field_id, $user_value);
                        // Maintain backwards compatibility with older extensions that use the ninja_forms_save_sub_args filter.
                        $data[] = array('field_id' => $field_id, 'user_value' => $user_value);
                        //
                    }
                }
            }
        }
        // Maintain backwards compatibility with older extensions that still use the ninja_forms_save_sub_args filter.
        $args = apply_filters('ninja_forms_save_sub_args', array('sub_id' => $sub_id, 'form_id' => $form_id, 'data' => serialize($data)));
        ninja_forms_update_sub($args);
        //
        do_action('nf_save_sub', $sub_id);
    }
}
Ejemplo n.º 2
0
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);
        }
    }
}
Ejemplo n.º 3
0
/**
 * ninja_forms_insert_sub() has been deprecated in favour of Ninja_Forms()->subs()->create( $form_id );
 * Because submissions are now a CPT, this function will only return false. 
 * Please replace any instances of this function with the replacement.
 * 
 * @since 2.7
 */
function ninja_forms_insert_sub($args)
{
    if (!isset($args['form_id'])) {
        return false;
    }
    $form_id = $args['form_id'];
    $sub_id = Ninja_Forms()->subs()->create($form_id);
    $args['sub_id'] = $sub_id;
    ninja_forms_update_sub($args);
    return $sub_id;
}
Ejemplo n.º 4
0
function ninja_forms_edit_sub_save_values()
{
    global $ninja_forms_processing;
    $sub_id = $ninja_forms_processing->get_form_setting('sub_id');
    $form_id = $ninja_forms_processing->get_form_ID();
    $user_id = $ninja_forms_processing->get_user_ID();
    $sub_row = ninja_forms_get_sub_by_id($sub_id);
    if (isset($sub_row['status'])) {
        $status = $sub_row['status'];
    } else {
        $status = '';
    }
    if (isset($sub_row['action'])) {
        $action = $sub_row['action'];
    } else {
        $action = '';
    }
    $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));
        }
    }
    $args = array('form_id' => $form_id, 'user_id' => $user_id, 'status' => $status, 'action' => $action, 'data' => serialize($sub_data), 'sub_id' => $sub_id);
    $args = apply_filters('ninja_forms_edit_sub_args', $args);
    ninja_forms_update_sub($args);
}
Ejemplo n.º 5
0
function ninja_forms_edit_sub()
{
    global $wpdb;
    $sub_id = absint($_REQUEST['sub_id']);
    $sub_data = $_REQUEST['sub_data'];
    $args = array('sub_id' => $sub_id, 'data' => $sub_data);
    ninja_forms_update_sub($args);
    die;
}
Ejemplo n.º 6
0
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', '');
        }
    }
}