GithubHelp home page GithubHelp logo

minphp-input's People

Contributors

clphillips avatar jreissmueller avatar tysonphillips avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

minphp-input's Issues

"_linked" field sets entire input data set to null if field is not provided

The update from #5 should be updated from:

if (!array_key_exists($index, $data_set)) {
    $data_set = null;
    break;
}

to

if (!array_key_exists($index, $data_set)) {
    continue 2;
}

This accurately keeps the $param null (line 460), and also does not override the $data_set with null. That is, we do not want the $data_set to be null for the _linked parameter that is set to null, but rather we want the $data_set to remain unchanged and the _linked parameter to be intepretted as null.

The difference is noticable when we link array fields, e.g.:

$rules = array(
    'test[][value]' => array(
        'invalid' => array(
            'rule' => array(
                function ($value, $option) {
                    return true;
                },
                array('_linked' => 'test[][option]')
            ),
            'message' => 'Test'
        )
    )
);

$vars = array('test' => array(array('value' => 1)));

$input = new Input();
$input->setRules($rules);
$input->validates($vars);

print_r($vars);

The printed output of $vars is

array(
    'test' => array(
        array(
            'value' => 1
            'option' => null
        )
    )
)

This causes $vars['test'][0] to contain an option key, set to null, that it should not have. This task would resolve that issue.

_linked field defaults to entire input array if field is not provided

When validating rules, or setting pre/post formatting, "_linked" fields can be included and past along to a callback function. However, if the field referenced via "_linked" is not set in the input array being validated against, then the value of the field is set to the entire input array. Instead, the value should be null since it is not set.

e.g.

$rules = [
    'test' => [
        'invalid' => [
            'rule' => [
                function ($test, $option) {
                    var_dump($test); // 'abc'
                    var_dump($option); // ['test' => 'abc', 'x' => 100, 'y' => 200]
                    return false;
                },
                ['_linked' => 'option']
            ],
            'message' => 'Test Error'
        ]
    ]
];

$data = ['test' => 'abc', 'x' => 100, 'y' => 200];
$input = new Input();
$input->setRules($rules);
$input->validates($data);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.