• Hi All,

    I want to ask how to set validation on image_advanced fields? I try to set ‘required’ validation on image_advanced, when there is no image, it says ‘The field is required’, but when I choose an image, it keeps saying ‘The field is required’, and the form cannot be submitted. The metabox code is as below :

    $meta_boxes[] = array(
    	'id'         => 'about',
    	'title'      => __( 'About Us', 'meta-box' ),
    	'post_types' => array( 'about_us' ),
    	'context'    => 'normal',
    	'priority'   => 'high',
    	'autosave'   => true,
    	'fields'     => array(
    		array(
    			'name'  => __( 'Banner Image', 'meta-box' ),
    			'id'    => "image_banner",
    			'type'  => 'image_advanced',
    			'max_file_uploads' => 1
    		)
    	),
    	'validation' => array(
    		'rules'    => array(
    			"image_banner" => array(
    				'required'  => true
    			)
    		),
    		'messages' => array(
    			"image_banner" => array(
    				'required'  => __( 'Banner Image is required', 'meta-box' ),
    			)
    		)
    	)
    );

    Thank you.

The topic ‘Validation on image_advanced’ is closed to new replies.