Giter VIP home page Giter VIP logo

form's People

Contributors

mychidarko avatar rasalas avatar toddy15 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

form's Issues

Null check problem with the function "getDotNotatedValue($array, $key)".

When I try to validate data not present in the request() method, the validation function doesn't check if the value is null before trying to explode it.

{"credentials":{"username":null,"phone":null,"password":null}}<!--

TypeError: explode(): Argument leafsphp/leaf#2 ($string) must be of type string, int given in file C:\dev\leaf_projects\annonces_backend\vendor\leafs\form\src\Form.php on line 246
Stack trace:

  1. TypeError->() C:\dev\leaf_projects\annonces_backend\vendor\leafs\form\src\Form.php:246
  2. explode() C:\dev\leaf_projects\annonces_backend\vendor\leafs\form\src\Form.php:246
  3. Leaf\Form->getDotNotatedValue() C:\dev\leaf_projects\annonces_backend\vendor\leafs\form\src\Form.php:211
  4. Leaf\Form->validate() C:\dev\leaf_projects\annonces_backend\app\controllers\Auth\RegisterController.php:14
  5. App\Controllers\Auth\RegisterController->store() C:\dev\leaf_projects\annonces_backend\vendor\leafs\router\src\Router\Core.php:550
  6. call_user_func_array() C:\dev\leaf_projects\annonces_backend\vendor\leafs\router\src\Router\Core.php:550
  7. Leaf\Router\Core->invoke() C:\dev\leaf_projects\annonces_backend\vendor\leafs\router\src\Router\Core.php:521
  8. Leaf\Router\Core->handle() C:\dev\leaf_projects\annonces_backend\vendor\leafs\router\src\Router\Core.php:466
  9. Leaf\Router\Core->run() C:\dev\leaf_projects\annonces_backend\vendor\leafs\leaf\src\App.php:382
  10. Leaf\App->run() C:\dev\leaf_projects\annonces_backend\vendor\leafs\mvc-core\src\Core.php:121
  11. Leaf\Core->runApplication() C:\dev\leaf_projects\annonces_backend\public\index.php:110
  12. require_once() C:\dev\leaf_projects\annonces_backend\index.php:28

Add validation for multidimensional arrays

Hi,

in an API project, I tried to validate nested values - like the value of the following: $data['name']['first']:

<?php

$data = [
  'name' => [
    'first' => 'Jane',
    'last' => 'Doe'
  ],
  'email' => '[email protected]',
  'password' => 'password1234',
];

...which didn't work.
I couldn't find anything in the documentation, tried the dot notation that I knew from Laravel - didn't work.
I looked at the source, found out it only works for one-dimensional arrays, and then just implemented it for myself.

with my change, this works:

<?php

$data = [
  'name' => [
    'first' => 'Jane',
    'last' => 'Doe',
  ],
  'email' => '[email protected]',
  'password' => 'password1234',
];

$success = form()->validate($data, [
  'name.first' => 'required',
  'name.last' => 'required',
  'email' => 'required|email',
  'password' => 'required|min:8'
]);

if ($success) {
  // do something
} else {
  // get errors
  $errors = form()->errors();
}

I've never created pull requests before (I basically work alone), I tried to follow the contribution guide, but I'm not 100% sure if I'm doing it correctly here, as I already had working code before writing this issue.

I'll create a pull request with my changes and I will try to link this issue to it.

The tests that I added, all PASS.
(only something in Tests\arraytest, that didn't work before, fails).

The Contribution Guide tells me to "open a suggestion issue first with the suggestion or feature request tag". I can't find that here.

This is obviously only a suggested feature - so a feature request for now - maybe you'd want to implement it differently or I missed something.

I'd like some pointers ;)
Thanks!

form validate "noSpaces" invalid

Form::validate([
"password" => ["required", "noSpaces"]
]);

No matter whether you enter a space or not, you will be prompted with an error.

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.