Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation for empty array fields doesn't seem to work #315

Closed
ocean90 opened this issue Nov 12, 2020 · 6 comments
Closed

Validation for empty array fields doesn't seem to work #315

ocean90 opened this issue Nov 12, 2020 · 6 comments

Comments

@ocean90
Copy link
Contributor

ocean90 commented Nov 12, 2020

Example:

$data = [
	'array_data_required' => [],
	'array_data_size_one' => [],
];

$is_valid = GUMP::is_valid(
	$data,
	[
		'array_data_required' => 'required',
		'array_data_size_one' => 'valid_array_size_equal,1',
	]
);

var_dump( $is_valid ); // bool(true)

In the above example I'd expect that the result is not valid for both fields since their value is empty. Am I'm missing something here?

@ocean90 ocean90 changed the title Validation for empty array fields don't seem to work Validation for empty array fields doesn't seem to work Nov 12, 2020
@Raphael-MOUQUIN
Copy link

no, they should NOT be valid imho

@Raphael-MOUQUIN
Copy link

but maybe coz they are empty?

here you cast to light an important "feature" , //thinking about empty forms//

it shows i guess it's the programmer's responsability to chek for empty data PRIOR validation, humm... there must be some default settings regarding empty data sets ; i'm going to investigate the unit tests right now. Hang on

@Raphael-MOUQUIN
Copy link

can't find. they are 43 Validators in https://github.com/Wixel/GUMP/tree/master/tests/Validators but none for empty array()

@Raphael-MOUQUIN
Copy link

in those 43 files they are a total of 38 calls to function testWhenInputIsEmptyAndNotRequiredIsSuccess() but can't find empty array() tests

@Raphael-MOUQUIN
Copy link

P.S. @ocean90 for your issue to be seen i'd suggest you rename its title to e.g. Empty [] arrays NOT ... or EMPTY ARRAYS .... smth

filisko added a commit that referenced this issue Jul 15, 2022
@filisko
Copy link
Collaborator

filisko commented Jul 15, 2022

Fixed now.

Way to use it:

$is_valid = GUMP::is_valid(
	$data,
	[
		'array_data_required' => 'required|valid_array_size_equal,1'
	]
);

@filisko filisko closed this as completed Jul 15, 2022
filisko added a commit that referenced this issue Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants