leafsphp / form Goto Github PK
View Code? Open in Web Editor NEW๐ Leaf form module
Home Page: https://leafphp.dev/modules/forms/
๐ Leaf form module
Home Page: https://leafphp.dev/modules/forms/
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:
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([
"password" => ["required", "noSpaces"]
]);
No matter whether you enter a space or not, you will be prompted with an error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.