Skip to content

validate_callback problem #3957

@syrian-dev

Description

@syrian-dev

hello
i have problem wheni am using validate_callback function
when try to save post with empty season_id
i get an error notice at the top "1 warnings(s) were found!"
but the message did not showup under "select input"

even with value passed
the same error notice showup
i try to figure out what happning

so in file redux-framework\redux-core\inc\classes\class-redux-validation.php
i addit var_dump() under validate function
like this

		public function validate( array $plugin_options, array $options, array $sections ): array {
			$core = $this->core();
			var_dump($sections); die;

i see the sections from series_metabox not from season_metabox
but i save a post have section season_metabox !!
can you help me guys
i am stuck on this problem for 2 days
sorry for my poor english

<?php
function is_int_value($field, $value, $existing_value) {
		$error   = false;
		$warning = false;

		// Do your validation.
		if (intval($value) == 0 ) {
			$warning = true;
			$value   = $existing_value;
		}

		$return['value'] = $value;

		if ( true === $warning ) {
			$field['msg']      = 'your custom warning message';
			$return['warning'] = $field;
		}

		return $return;
}

Redux_Metaboxes::set_box(
	$opt_name,
	array(
		'id'         => 'series_metabox',
		'title'      => esc_html__( 'TV Show Data', 'egybest' ),
		'post_types' => array('episode'),
		'position'   => 'normal', // normal, advanced, side.
		'priority'   => 997,   // high, core, default, low.
		'context' => 'after_editor',
		'sections'   => array(
			array(
				'id'     => 'episode-data',
				'title'  => esc_html__( 'Episode information', 'egybest' ),
				'desc'   => '',
				'icon'   => 'el el-screen',
				'fields' => array(
					array(
						'id' 	=> 'seasons_id',
						'type' 	=> 'select',
						'data'  => 'posts',
						'title'    => esc_html__( 'Select Season', 'egybest' ),
						'ajax_save'	=> false, // Force page load when this changes
						'validate_callback' => 'is_int_value',
						'args'  => array(
							'post_type'      => 'season',
							'posts_per_page' => -1,
							'orderby'        => 'title',
							'order'          => 'ASC',
							'hide_empty' 	 => false,
						)
					)
				)
			)
		)
	)
);



// Season Meta Box
Redux_Metaboxes::set_box(
	$opt_name,
	array(
		'id'         => 'season_metabox',
		'title'      => esc_html__( 'TV Show Data ', 'egybest' ),
		'post_types' => array('season'),
		'position'   => 'normal', // normal, advanced, side.
		'priority'   => 998,   // high, core, default, low.
		'context' => 'after_editor',
		'sections'   => array(
			array(
				'title'  => esc_html__( 'Season information', 'egybest' ),
				'id'     => 'season_data',
				'desc'   => '',
				'icon'   => 'el el-screen',
				'fields' => array(
					array(
						'id' 		=> 'series_id',
						'type' 		=> 'select',
						'data'  	=> 'posts',
						'ajax_save'	=> false, // Force page load when this changes
						'title'		=> esc_html__( 'Select TV Show', 'egybest' ),
						'validate_callback' => 'is_int_value',
						'args'  => array(
							'post_type'      => 'tv_show',
							'posts_per_page' => -1,
							'orderby'        => 'title',
							'order'          => 'ASC',
							'hide_empty' 	 => false,
						),
					),
					array(
						'id'       => 'season_number',
						'type'     => 'number',
						'title'    => esc_html__( 'Season Number', 'egybest' ),
						'validate' => 'numeric',
					),
				),
			)
		)
	)
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions