$data['title.error_class'] = '';
$data['callback.error_class'] = '';
// Init data points
$data['id'] = '';
$data['title'] = '';
$data['context'] = 'advanced';
$data['priority'] = 'default';
$data['callback'] = '';
$data['callback_args'] = '';
$data['visibility_control'] = '';
$data['style'] = file_get_contents(CCTM_PATH . '/css/validation.css');
// Save if submitted...
if (!empty($_POST) && check_admin_referer($data['action_name'], $data['nonce_name'])) {
    $def = CCTM_Metabox::sanitize($_POST);
    unset($def['old_id']);
    if (CCTM_Metabox::is_valid_def($_POST)) {
        CCTM::$data['metabox_defs'][$def['id']] = $def;
        CCTM::set_flash(CCTM::format_msg(__('Metabox created.', CCTM_TXTDOMAIN)));
        $continue_editing = CCTM::get_value($_POST, 'continue_editing');
        unset($_POST);
        if ($continue_editing) {
            CCTM::redirect('?page=cctm&a=edit_metabox&id=' . $def['id']);
        } else {
            CCTM::redirect('?page=cctm');
        }
        return;
    } else {
        $data['msg'] = CCTM::format_error_msg(CCTM_Metabox::$errors, __('Please correct the following problems.', CCTM_TXTDOMAIN));
        foreach (CCTM_Metabox::$errors as $field => $error) {
            $data[$field . '.error'] = sprintf('<span class="cctm_validation_error">%s</span>', $error);
            $data[$field . '.error_class'] = 'cctm_validation_error';
$field_data = array();
// Data object we will save
// Init Error bits
$data['id.error'] = '';
$data['title.error'] = '';
$data['callback.error'] = '';
$data['id.error_class'] = '';
$data['title.error_class'] = '';
$data['callback.error_class'] = '';
$data['style'] = file_get_contents(CCTM_PATH . '/css/validation.css');
// Save if submitted...
if (!empty($_POST) && check_admin_referer($data['action_name'], $data['nonce_name'])) {
    //print_r($_POST); exit;
    $def = CCTM_Metabox::sanitize($_POST);
    //print_r($def); exit;
    if (CCTM_Metabox::is_valid_def($_POST, true)) {
        $data['msg'] = CCTM::format_msg(__('Metabox updated.', CCTM_TXTDOMAIN));
        // Find any refs to the old id and update them
        if ($def['id'] != $def['old_id']) {
            if (isset(CCTM::$data['post_type_defs']) && is_array(CCTM::$data['post_type_defs'])) {
                foreach (CCTM::$data['post_type_defs'] as $pt => $ptd) {
                    if (isset($ptd['map_field_metabox']) && is_array($ptd['map_field_metabox'])) {
                        foreach ($ptd['map_field_metabox'] as $cf => $mb) {
                            if ($mb == $def['old_id']) {
                                CCTM::$data['post_type_defs'][$pt]['map_field_metabox'][$cf] = $def['id'];
                            }
                        }
                    }
                }
            }
        }