fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

Validation::run() can't get value with custom parameters of nested array #1443

Closed takyam-git closed 11 years ago

takyam-git commented 11 years ago
$val = Validation::forge();
$val->add_field('files.0.name', 'file name 0', 'required');
$val->add_field('files.1.name', 'file name 1', 'required');

//not posted but need validation parameters. (ex $_FILES)
$not_posted_parameters = array(
    'files' => array(
        '0' => array(
            'name' => 'file0.jpg',
        ),
        '1' => array(
            'name' => 'file1.jpg',
        ),
    ),
);

$val->run($not_posted_parameters); //false

expected return is true, but it's returned false. but parameters if in post and set 1st argument of run(), returned true.

$_POST = $not_posted_parameters;
$val->run(); // false
$val->run($not_posted_parameters); //true

workaround solution is

$flatten_parameters = Arr::flatten($not_posted_parameters, '.');
$val->run($flatten_parameters); //true
takyam-git commented 11 years ago

thanks!!

Art4 commented 11 years ago

Btw: The run method is completly missing in the docs: http://fuelphp.com/dev-docs/classes/validation/methods.html

WanWizard commented 11 years ago

See https://github.com/fuel/docs/issues/73