/**
 * Filters groups on post edit page.
 *
 * @param type $groups
 * @param type $post
 * @return type
 */
function wpcf_cd_post_groups_filter($groups, $post, $context)
{
    if ($context != 'group') {
        return $groups;
    }
    foreach ($groups as $key => &$group) {
        $conditions = null;
        if (array_key_exists('conditional_display', $group) && array_key_exists('conditions', $group['conditional_display'])) {
            $conditions = $group['conditional_display'];
        } else {
            $conditions = get_post_meta($group['id'], '_wpcf_conditional_display', true);
        }
        if (!empty($conditions['conditions'])) {
            $meta_box_id = "wpcf-group-{$group['slug']}";
            $prefix = 'wpcf-';
            $suffix = '';
            $cond = array();
            if (isset($post->ID)) {
                $cond_values = get_post_custom($post->ID);
            } else {
                $cond_values = array();
            }
            $_cond_values = array();
            foreach ($cond_values as $k => $v) {
                $v = maybe_unserialize($v[0]);
                $_cond_values[$k . $suffix] = is_array($v) ? strval(array_shift($v)) : $v;
            }
            unset($cond_values);
            $cond = array();
            if (!empty($conditions['custom_use'])) {
                if (!empty($conditions['custom'])) {
                    $custom = WPToolset_Types::getCustomConditional($conditions['custom']);
                    $passed = WPToolset_Forms_Conditional::evaluateCustom($custom['custom'], $_cond_values);
                    $cond = array('custom' => $custom['custom'], 'custom_use' => true);
                }
            } else {
                $cond = array('relation' => $conditions['relation'], 'conditions' => array(), 'values' => $_cond_values);
                foreach ($conditions['conditions'] as $d) {
                    $c_field = types_get_field($d['field']);
                    if (!empty($c_field)) {
                        $_c = array('id' => wpcf_types_get_meta_prefix($c_field) . $d['field'] . $suffix, 'type' => $c_field['type'], 'operator' => $d['operation'], 'args' => array($d['value']));
                        $cond['conditions'][] = $_c;
                    }
                }
                $passed = wptoolset_form_conditional_check(array('conditional' => $cond));
            }
            $data = array('id' => $meta_box_id, 'conditional' => $cond);
            wptoolset_form_add_conditional('post', $data);
            if (!$passed) {
                $group['_conditional_display'] = 'failed';
            } else {
                $group['_conditional_display'] = 'passed';
            }
        }
    }
    return $groups;
}
示例#2
0
/**
 * Important save_post hook.
 *
 * Core function. Works and stable. Do not move or change.
 * If required, add hooks only.
 *
 * @internal breakpoint
 * @param type $post_ID
 * @param type $post
 */
function wpcf_admin_post_save_post_hook($post_ID, $post)
{
    if (defined('WPTOOLSET_FORMS_VERSION')) {
        global $wpcf;
        $errors = false;
        // Do not save post if is type of
        if (in_array($post->post_type, array('revision', 'view', 'view-template', 'cred-form', 'nav_menu_item', 'mediapage'))) {
            return false;
        }
        $_post_wpcf = array();
        if (!empty($_POST['wpcf'])) {
            $_post_wpcf = $_POST['wpcf'];
        }
        /**
         * handle checkbox
         */
        if (array_key_exists('_wptoolset_checkbox', $_POST) && is_array($_POST['_wptoolset_checkbox'])) {
            foreach ($_POST['_wptoolset_checkbox'] as $key => $field_value) {
                $field_slug = preg_replace('/^wpcf\\-/', '', $key);
                if (array_key_exists($field_slug, $_post_wpcf)) {
                    continue;
                }
                $_post_wpcf[$field_slug] = false;
            }
        }
        if (count($_post_wpcf)) {
            /**
             * check some attachment to delete
             */
            $delete_attachments = apply_filters('wpcf_delete_attachments', true);
            $images_to_delete = array();
            if ($delete_attachments && isset($_POST['wpcf']) && array_key_exists('delete-image', $_POST['wpcf']) && is_array($_POST['wpcf']['delete-image'])) {
                foreach ($_POST['wpcf']['delete-image'] as $image) {
                    $images_to_delete[$image] = 1;
                }
            }
            foreach ($_post_wpcf as $field_slug => $field_value) {
                // Get field by slug
                $field = wpcf_fields_get_field_by_slug($field_slug);
                if (empty($field)) {
                    continue;
                }
                // Skip copied fields
                if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
                    continue;
                }
                $_field_value = !types_is_repetitive($field) ? array($field_value) : $field_value;
                // Set config
                $config = wptoolset_form_filter_types_field($field, $post_ID, $_post_wpcf);
                /**
                 * remove from images_to_delete if user add again
                 */
                if ($delete_attachments && 'image' == $config['type']) {
                    $images = $_field_value;
                    if (!is_array($images)) {
                        $images = array($images);
                    }
                    foreach ($images as $image) {
                        if (array_key_exists($image, $images_to_delete)) {
                            unset($images_to_delete[$image]);
                        }
                    }
                }
                foreach ($_field_value as $_k => $_val) {
                    // Check if valid
                    $validation = wptoolset_form_validate_field('post', $config, $_val);
                    $conditional = wptoolset_form_conditional_check($config);
                    $not_valid = is_wp_error($validation) || !$conditional;
                    if (is_wp_error($validation)) {
                        $errors = true;
                        $_errors = $validation->get_error_data();
                        $_msg = sprintf(__('Field "%s" not updated:', 'wpcf'), $field['name']);
                        wpcf_admin_message_store($_msg . ' ' . implode(', ', $_errors), 'error');
                    }
                    if ($not_valid) {
                        if (types_is_repetitive($field)) {
                            unset($field_value[$_k]);
                        } else {
                            break;
                        }
                    }
                }
                // Save field
                if (types_is_repetitive($field)) {
                    $wpcf->repeater->set($post_ID, $field);
                    $wpcf->repeater->save($field_value);
                } else {
                    if (!$not_valid) {
                        $wpcf->field->set($post_ID, $field);
                        $wpcf->field->save($field_value);
                    }
                }
                do_action('wpcf_post_field_saved', $post_ID, $field);
                // TODO Move to checkboxes
                if ($field['type'] == 'checkboxes') {
                    if (!empty($field['data']['options'])) {
                        $update_data = array();
                        foreach ($field['data']['options'] as $option_id => $option_data) {
                            if (!isset($_POST['wpcf'][$field['id']][$option_id])) {
                                if (isset($field['data']['save_empty']) && $field['data']['save_empty'] == 'yes') {
                                    $update_data[$option_id] = 0;
                                }
                            } else {
                                $update_data[$option_id] = $_POST['wpcf'][$field['id']][$option_id];
                            }
                        }
                        update_post_meta($post_ID, $field['meta_key'], $update_data);
                    }
                }
            }
            /**
             * delete images
             */
            if ($delete_attachments && !empty($images_to_delete)) {
                $args = array('post_parent' => $post_ID, 'posts_per_page' => -1);
                $children_array = get_children($args);
                foreach ($children_array as $child) {
                    if (!array_key_exists($child->guid, $images_to_delete)) {
                        continue;
                    }
                    wp_delete_attachment($child->ID);
                }
            }
        }
        if ($errors) {
            update_post_meta($post_ID, '__wpcf-invalid-fields', true);
        }
        do_action('wpcf_post_saved', $post_ID);
        return;
    }
    // OLD
    global $wpcf;
    // Basic cheks
    /*
     * Allow this hook to be triggered only if Types form is submitted
     */
    //    if ( !isset( $_POST['_wpcf_post_wpnonce'] ) || !wp_verify_nonce( $_POST['_wpcf_post_wpnonce'],
    //                    'update-' . $post->post_type . '_' . $post_ID ) ) {
    //        return false;
    //    }
    /*
     * Do not save post if is type of:
     * revision
     * attachment
     * wp-types-group
     * view
     * view-template
     * cred-form
     */
    if (in_array($post->post_type, $wpcf->excluded_post_types)) {
        return false;
    }
    /*
     *
     *
     * Get all groups connected to this $post
     */
    $groups = wpcf_admin_post_get_post_groups_fields($post);
    if (empty($groups)) {
        return false;
    }
    $all_fields = array();
    $_not_valid = array();
    $_error = false;
    /*
     *
     *
     * Loop over each group
     *
     * TODO Document this
     * Connect 'wpcf-invalid-fields' with all fields
     */
    foreach ($groups as $group) {
        if (isset($group['fields'])) {
            // Process fields
            $fields = wpcf_admin_post_process_fields($post, $group['fields'], true, false, 'validation');
            // Validate fields
            $form = wpcf_form_simple_validate($fields);
            $all_fields = $all_fields + $fields;
            // Collect all not valid fields
            if ($form->isError()) {
                $_error = true;
                // Set error only to true
                $_not_valid = array_merge($_not_valid, (array) $form->get_not_valid());
            }
        }
    }
    // Set fields
    foreach ($all_fields as $k => $v) {
        // only Types field
        if (empty($v['wpcf-id'])) {
            continue;
        }
        $_temp = new WPCF_Field();
        $_temp->set($wpcf->post, $v['wpcf-id']);
        $all_fields[$k]['_field'] = $_temp;
    }
    foreach ($_not_valid as $k => $v) {
        // only Types field
        if (empty($v['wpcf-id'])) {
            continue;
        }
        $_temp = new WPCF_Field();
        $_temp->set($wpcf->post, $v['wpcf-id']);
        $_not_valid[$k]['_field'] = $_temp;
    }
    /*
     *
     * Allow interaction here.
     * Conditional will set $error to false if field is conditional
     * and not submitted.
     */
    $error = apply_filters('wpcf_post_form_error', $_error, $_not_valid, $all_fields);
    $not_valid = apply_filters('wpcf_post_form_not_valid', $_not_valid, $_error, $all_fields);
    // Notify user about error
    if ($error) {
        wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error');
    }
    /*
     * Save invalid elements so user can be informed after redirect.
     */
    if (!empty($not_valid)) {
        update_post_meta($post_ID, 'wpcf-invalid-fields', $not_valid);
    }
    /*
     *
     *
     *
     *
     * Save meta fields
     */
    if (!empty($_POST['wpcf'])) {
        foreach ($_POST['wpcf'] as $field_slug => $field_value) {
            // Get field by slug
            $field = wpcf_fields_get_field_by_slug($field_slug);
            if (empty($field)) {
                continue;
            }
            // Set field
            $wpcf->field->set($post_ID, $field);
            // Skip copied fields
            // CHECKPOINT
            if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
                continue;
            }
            // Don't save invalid
            // CHECKPOINT
            if (isset($not_valid[$field['slug']])) {
                continue;
            }
            /*
             *
             *
             * Saving fields
             * @since 1.2
             *
             * We changed way repetitive fields are saved.
             * On each save fields are rewritten and order is saved in
             * '_$slug-sort-order' meta field.
             */
            /*
             *
             * We marked fields as repetitive in POST['__wpcf_repetitive']
             * Without this check we won't save any.
             * @see WPCF_Repeater::get_fields_form()
             */
            if (isset($_POST['__wpcf_repetitive'][$wpcf->field->slug])) {
                /*
                 * Use here WPCF_Repeater class.
                 * WPCF_Repeater::set() - switches to current post
                 * WPCF_Repeater::save() - saves repetitive field
                 */
                $wpcf->repeater->set($post_ID, $field);
                $wpcf->repeater->save();
            } else {
                /*
                 * Use WPCF_Field::save()
                 */
                $wpcf->field->save();
            }
            do_action('wpcf_post_field_saved', $post_ID, $field);
        }
    }
    /*
     * Process checkboxes
     *
     * TODO Revise and remove
     * Since Types 1.1.5 we moved this check to embedded/includes/checkbox.php
     * checkbox.php added permanently to bootstrap.
     */
    foreach ($all_fields as $field) {
        if (!isset($field['#type'])) {
            continue;
        }
        //        if ( $field['#type'] == 'checkbox'
        //                && !isset( $_POST['wpcf'][$field['wpcf-slug']] ) ) {
        //            $field_data = wpcf_admin_fields_get_field( $field['wpcf-id'] );
        //            if ( isset( $field_data['data']['save_empty'] )
        //                    && $field_data['data']['save_empty'] == 'yes' ) {
        //                update_post_meta( $post_ID,
        //                        wpcf_types_get_meta_prefix( $field ) . $field['wpcf-slug'],
        //                        0 );
        //            } else {
        //                delete_post_meta( $post_ID,
        //                        wpcf_types_get_meta_prefix( $field ) . $field['wpcf-slug'] );
        //            }
        //        }
        if ($field['#type'] == 'checkboxes') {
            $field_data = wpcf_admin_fields_get_field($field['wpcf-id']);
            if (!empty($field_data['data']['options'])) {
                $update_data = array();
                foreach ($field_data['data']['options'] as $option_id => $option_data) {
                    if (!isset($_POST['wpcf'][$field['wpcf-slug']][$option_id])) {
                        if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') {
                            $update_data[$option_id] = 0;
                        }
                    } else {
                        $update_data[$option_id] = $_POST['wpcf'][$field['wpcf-slug']][$option_id];
                    }
                }
                update_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], $update_data);
            }
        }
    }
    do_action('wpcf_post_saved', $post_ID);
}
/**
 * The save_post hook.
 *
 * @param int $post_ID
 * @param WP_Post $post
 * @since unknown
 */
function wpcf_admin_post_save_post_hook($post_ID, $post)
{
    // Apparently, some things are *slightly* different when saving a child post in the Post relationships metabox.
    // Ugly hack that will go away with m2m.
    //
    // Note: The types_updating_child_post filter is needed for a situation when user clicks on the Update button
    // for the parent post. In that case we don't get enough information to determine if a child post is being updated.
    $is_child_post_update = 'wpcf_ajax' == wpcf_getget('action') && 'pr_save_child_post' == wpcf_getget('wpcf_action') || apply_filters('types_updating_child_post', false);
    global $wpcf;
    $errors = false;
    // Do not save post if is type of
    if (in_array($post->post_type, array('revision', 'view', 'view-template', 'cred-form', 'cred-user-form', 'nav_menu_item', 'mediapage'))) {
        return;
    }
    $_post_wpcf = array();
    if (!empty($_POST['wpcf'])) {
        $_post_wpcf = $_POST['wpcf'];
    }
    // handle checkbox
    if (array_key_exists('_wptoolset_checkbox', $_POST) && is_array($_POST['_wptoolset_checkbox'])) {
        foreach ($_POST['_wptoolset_checkbox'] as $key => $field_value) {
            $field_slug = preg_replace('/^wpcf\\-/', '', $key);
            if (array_key_exists($field_slug, $_post_wpcf)) {
                continue;
            }
            $_post_wpcf[$field_slug] = false;
        }
    }
    // handle radios
    if (array_key_exists('_wptoolset_radios', $_POST) && is_array($_POST['_wptoolset_radios'])) {
        foreach ($_POST['_wptoolset_radios'] as $key => $field_value) {
            $field_slug = preg_replace('/^wpcf\\-/', '', $key);
            if (array_key_exists($field_slug, $_post_wpcf)) {
                continue;
            }
            $_post_wpcf[$field_slug] = false;
        }
    }
    if (count($_post_wpcf)) {
        $add_error_message = true;
        if (isset($_POST['post_id']) && $_POST['post_id'] != $post_ID) {
            $add_error_message = false;
        }
        // check some attachment to delete
        $delete_attachments = apply_filters('wpcf_delete_attachments', true);
        $images_to_delete = array();
        if ($delete_attachments && isset($_POST['wpcf']) && array_key_exists('delete-image', $_POST['wpcf']) && is_array($_POST['wpcf']['delete-image'])) {
            foreach ($_POST['wpcf']['delete-image'] as $image) {
                $images_to_delete[$image] = 1;
            }
        }
        foreach ($_post_wpcf as $field_slug => $field_value) {
            // Get field by slug
            $field = wpcf_fields_get_field_by_slug($field_slug);
            if (empty($field)) {
                continue;
            }
            // Skip copied fields
            if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
                continue;
            }
            // This is (apparently) expected for repetitive fields...
            if ($is_child_post_update && types_is_repetitive($field)) {
                $field_value = array($field_value);
            }
            $_field_value = !types_is_repetitive($field) ? array($field_value) : $field_value;
            // Set config
            $config = wptoolset_form_filter_types_field($field, $post_ID, $_post_wpcf);
            // remove from images_to_delete if user add again
            if ($delete_attachments && 'image' == $config['type']) {
                $images = $_field_value;
                if (!is_array($images)) {
                    $images = array($images);
                }
                foreach ($images as $image) {
                    if (array_key_exists($image, $images_to_delete)) {
                        unset($images_to_delete[$image]);
                    }
                }
            }
            // add filter to remove field name from error message
            // This filter is toolset-common/toolset-forms/classes/class.validation.php
            add_filter('toolset_common_validation_add_field_name_to_error', '__return_false', 1234, 1);
            foreach ($_field_value as $_k => $_val) {
                // Check if valid
                $validation = wptoolset_form_validate_field('post', $config, $_val);
                $conditional = wptoolset_form_conditional_check($config);
                $not_valid = is_wp_error($validation) || !$conditional;
                if ($add_error_message && is_wp_error($validation)) {
                    $errors = true;
                    $_errors = $validation->get_error_data();
                    $_msg = sprintf(__('Field "%s" not updated:', 'wpcf'), $field['name']);
                    wpcf_admin_message_store($_msg . ' ' . implode(', ', $_errors), 'error');
                }
                if ($not_valid) {
                    if (types_is_repetitive($field)) {
                        unset($field_value[$_k]);
                    } else {
                        break;
                    }
                }
            }
            remove_filter('toolset_common_validation_add_field_name_to_error', '__return_false', 1234, 1);
            // Save field
            if (types_is_repetitive($field)) {
                $wpcf->repeater->set($post_ID, $field);
                $wpcf->repeater->save($field_value);
            } else {
                if (!$not_valid) {
                    $wpcf->field->set($post_ID, $field);
                    $wpcf->field->save($field_value);
                }
            }
            do_action('wpcf_post_field_saved', $post_ID, $field);
            // TODO Move to checkboxes
            if ($field['type'] == 'checkboxes') {
                if (!empty($field['data']['options'])) {
                    $update_data = array();
                    foreach ($field['data']['options'] as $option_id => $option_data) {
                        if (!isset($_POST['wpcf'][$field['id']][$option_id])) {
                            if (isset($field['data']['save_empty']) && $field['data']['save_empty'] == 'yes') {
                                $update_data[$option_id] = 0;
                            }
                        } else {
                            $update_data[$option_id] = $_POST['wpcf'][$field['id']][$option_id];
                        }
                    }
                    update_post_meta($post_ID, $field['meta_key'], $update_data);
                }
            }
        }
        // delete images
        if ($delete_attachments && !empty($images_to_delete)) {
            $args = array('post_parent' => $post_ID, 'posts_per_page' => -1);
            $children_array = get_children($args);
            foreach ($children_array as $child) {
                if (!array_key_exists($child->guid, $images_to_delete)) {
                    continue;
                }
                wp_delete_attachment($child->ID);
            }
        }
    }
    if ($errors) {
        update_post_meta($post_ID, '__wpcf-invalid-fields', true);
    }
    do_action('wpcf_post_saved', $post_ID);
    return;
}
示例#4
0
 /**
  * New validation using API calls from toolset-forms.
  *
  * Uses API cals
  * @uses wptoolset_form_validate_field()
  * @uses wptoolset_form_conditional_check()
  *
  * @todo Make it work with other fields (generic)
  *
  * @param type $post_id
  * @param type $values
  * @return boolean
  */
 function validate($post_id, $values)
 {
     $form_id = $this->form_id;
     $valid = true;
     // Loop over fields
     $form_source_data = $this->_formData->getForm()->post_content;
     preg_match_all("/\\[cred_show_group.*cred_show_group\\]/Uism", $form_source_data, $res);
     $conditional_group_fields = array();
     if (count($res[0]) > 0) {
         for ($i = 0, $res_limit = count($res[0]); $i < $res_limit; $i++) {
             preg_match_all("/field=\"([^\"]+)\"/Uism", $res[0][$i], $parsed_fields);
             if (count($parsed_fields[1]) > 0) {
                 for ($j = 0, $count_parsed_fields = count($parsed_fields); $j < $count_parsed_fields; $j++) {
                     if (!empty($parsed_fields[1][$j])) {
                         $conditional_group_fields[] = trim($parsed_fields[1][$j]);
                     }
                 }
             }
         }
     }
     foreach ($this->form_properties['fields'] as $field) {
         if (in_array(str_replace('wpcf-', '', $field['name']), $conditional_group_fields)) {
             continue;
         }
         // If Types field
         if (isset($field['plugin_type']) && $field['plugin_type'] == 'types') {
             $field_name = $field['name'];
             if (!isset($_POST[$field_name])) {
                 continue;
             }
             /* 	
                               // Adjust field ID
                               $field['id'] = strpos( $field['name'], 'wpcf-' ) === 0 ? substr( $field['name'], 5 ) : $field['name'];
                               // CRED have synonym 'text' for textfield
                               if ( $field['type'] == 'text' ) {
                               $field['type'] = 'textfield';
                               } */
             $field = wpcf_fields_get_field_by_slug(str_replace('wpcf-', '', $field['name']));
             if (empty($field)) {
                 continue;
             }
             // Skip copied fields
             if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
                 continue;
             }
             // Set field config
             $config = wptoolset_form_filter_types_field($field, $post_id);
             //Add custom colorpicer hexadecimal backend validator
             //Fix https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/193712665/comments
             //Todo in future add hexadecimal check in types
             if ($field['type'] == 'colorpicker') {
                 $config['validation']['hexadecimal'] = array('args' => array('$value', '1'), 'message' => 'Enter valid hexadecimal value');
             }
             if (isset($config['conditional']['values'])) {
                 foreach ($config['conditional']['values'] as $post_key => $post_value) {
                     if (isset($this->form_properties['fields'][$post_key])) {
                         $config['conditional']['values'][$post_key] = $this->form_properties['fields'][$post_key]['value'];
                     }
                 }
             }
             // Set values to loop over
             $_values = !empty($values[$field_name]) ? $values[$field_name]['value'] : null;
             if (empty($config['repetitive'])) {
                 $_values = array($_values);
             }
             // Loop over each value
             if (is_array($_values)) {
                 foreach ($_values as $value) {
                     $validation = wptoolset_form_validate_field($form_id, $config, $value);
                     $conditional = wptoolset_form_conditional_check($config);
                     /**
                      * add form_errors messages
                      */
                     if (is_wp_error($validation) && $conditional) {
                         $error_data = $validation->get_error_data();
                         if (isset($error_data[0])) {
                             $this->add_top_message($error_data[0], $config['id']);
                         } else {
                             $this->add_top_message($validation->get_error_message(), $config['id']);
                         }
                         $valid = false;
                         if (empty($ret_validation)) {
                             continue;
                         }
                         //                            foreach( $errors as $error ) {
                         //                                $error = explode( ' ', $error );
                         //                                $key = array_shift($error);
                         //                                $error = implode( ' ', $error );
                         //                                $this->form_errors[$key] = $error;
                         //                                $this->form_messages[$key] = $validation->get_error_message();
                         //                            }
                     }
                 }
             }
         } elseif (!isset($field['plugin_type']) && isset($field['validation'])) {
             if (!isset($_POST[$field['name']])) {
                 continue;
             }
             $config = array('id' => $field['name'], 'type' => $field['type'], 'slug' => $field['name'], 'title' => $field['name'], 'description' => '', 'name' => $field['name'], 'repetitive' => $field['repetitive'], 'validation' => $field['validation'], 'conditional' => array());
             $value = $field['value'];
             require_once WPTOOLSET_FORMS_ABSPATH . '/classes/class.types.php';
             $validation = array();
             foreach ($field['validation'] as $rule => $settings) {
                 if ($settings['active']) {
                     $id = $config['slug'];
                     $validation[$rule] = array('args' => isset($settings['args']) ? array_unshift($value, $settings['args']) : array($value, true), 'message' => WPToolset_Types::translate('field ' . $id . ' validation message ' . $rule, $settings['message']));
                 }
             }
             $config['validation'] = $validation;
             $validation = wptoolset_form_validate_field($form_id, $config, $value);
             if (is_wp_error($validation)) {
                 $error_data = $validation->get_error_data();
                 //TODO: replace id with name
                 if (isset($error_data[0])) {
                     $this->add_top_message($error_data[0], $config['id']);
                 } else {
                     $this->add_top_message($validation->get_error_message(), $config['id']);
                 }
                 $valid = false;
                 if (empty($ret_validation)) {
                     continue;
                 }
                 //                    foreach( $errors as $error ) {
                 //                        $error = explode( ' ', $error );
                 //                        $key = array_shift($error);
                 //                        $error = implode( ' ', $error );
                 //                        $this->form_errors[$key] = $error;
                 //                        $this->form_messages[$key] = $validation->get_error_message();
                 //                    }
             }
         }
     }
     return $valid;
 }