5959
6060Prior to installing ` validator package ` get the [ Composer] ( https://getcomposer.org ) dependency manager for PHP because it'll simplify installation.
6161
62- ```
62+ ``` txt
6363composer require tamedevelopers/validator
6464```
6565
6666## Instantiate — ` Instantiate class using `
67- ```
67+ - It's helper class can be called, using -- ` form() `
68+
69+ ``` php
6870require_once __DIR__ . '/vendor/autoload.php';
6971
7072use \Tamedevelopers\Validator\Validator;
7173
7274$form = new Validator();
7375```
7476
75- - or -- ` Helpers Function `
76- ```
77- $form = form();
78- ```
79-
8077## Laravel Support
8178- Now supports Laravel and with same Functionalities no different
8279 - ` use Tamedevelopers\Validator\Validator; `
8380
84- ```
81+ ``` php
8582public function save(Request $request){
8683
8784 $form = new Validator();
@@ -102,15 +99,14 @@ public function save(Request $request){
10299| ->get() | Convert Form request to ` GET ` only |
103100| ->all() | Convert Form request to ` any ` |
104101
105- ```
102+ ``` php
106103$form->post()->rules([
107104 //
108105]);
109106```
110107
111108## Global Configuration
112- - Helpers available to assist on easy configuration
113- - ` config_form() `
109+ - It's helper class can be called, using -- ` config_form() `
114110
115111| Keys | Description |
116112| -------------| -----------------------------------------|
@@ -119,7 +115,7 @@ $form->post()->rules([
119115| csrf_token | Boolean ` true\|false ` Default ` true ` |
120116| class | Assoc Array ` error\|success ` error class type to be returned on both success and failure |
121117
122- ```
118+ ``` php
123119config_form(
124120 request : 'POST',
125121 error_type : true,
@@ -142,15 +138,15 @@ config_form(
142138 - It's a function and you don't need to ` echo `
143139 - Use anywhere inside your HTML form
144140
145- ```
141+ ``` php
146142csrf();
147143```
148144![ Sample Csrf Form Input] ( https://raw.githubusercontent.com/tamedevelopers/validator/main/getErrorMessage.png )
149145
150146### Csrf Token
151147- This will return the ` csrf token ` string
152148
153- ```
149+ ``` php
154150csrf_token();
155151```
156152
@@ -167,7 +163,7 @@ csrf_token();
167163| false | ` Default ` Errors displayed one after another |
168164| true | This allow all errors to be displayed once, ` as an array ` |
169165
170- ```
166+ ``` php
171167$form->errorType(false);
172168```
173169
@@ -180,29 +176,29 @@ $form->errorType(false);
180176| false | ` Default ` Will disable ` csrf_token ` usage |
181177| true | This allow ` csrf_token ` per request only |
182178
183- ```
179+ ``` php
184180$form->token(false);
185181```
186182
187183### POST
188184- Set the Form Request to ` POST `
189185 - This will always override the ` config_form() ` settings
190186
191- ```
187+ ``` php
192188$form->post();
193189```
194190
195191### GET
196192- Set the Form Request to ` GET `
197193
198- ```
194+ ``` php
199195$form->get();
200196```
201197
202198### All
203199- Will automatically detect if request type is ` GET\|POST ` and get it's data.
204200
205- ```
201+ ``` php
206202$form->all()->rules([
207203 //
208204])
@@ -211,7 +207,7 @@ $form->all()->rules([
211207### Any
212208- same as ` all `
213209
214- ```
210+ ``` php
215211$form->any()->rules([
216212 //
217213])
@@ -226,15 +222,15 @@ $form->any()->rules([
226222| string | : country | : == | : 0 |
227223| email | : email | : | |
228224
229- ```
225+ ``` php
230226$form->rules([
231227 "string|country|==|0" => 'Please Select a Country',
232228 "email:email" => 'Please enter a valid email address',
233229])
234230```
235231
236232- HTML FORM Structure
237- ```
233+ ``` html
238234<form >
239235 <select name =" country" >
240236 <option value =" 0" >Select Country</option >
@@ -250,7 +246,7 @@ $form->rules([
250246### Validate
251247- Takes an [ optional] ` closure ` function as the param
252248
253- ```
249+ ``` php
254250$form->rules([
255251 "s:name" => 'Please enter a name',
256252])->validate(function($response){
@@ -264,7 +260,7 @@ $form->rules([
264260- Expects a ` closure ` function as the param
265261 - Message property will be empty string on success ` $response->message `
266262
267- ```
263+ ``` php
268264$form->rules([
269265 "s:name" => 'Please enter a name',
270266])->save(function(){
@@ -280,6 +276,8 @@ $form->rules([
280276| email | e | ` Email ` data validation |
281277| bool | b | ` Boolean ` data validation |
282278| string | s | ` String ` data validation |
279+ | html | - | ` html ` CMS/Blog content validation |
280+ | dev | - | ` dev ` CMS/Blog/Dev like content validation |
283281| str_len | sl | ` String Length ` validation |
284282| enum | en | ` Enum ` Forms ` checkbox \| radio ` or any form data that normally has no value when not checked |
285283| array | a | ` Array ` data validation |
@@ -309,7 +307,7 @@ $form->rules([
309307- Expects a ` closure ` function as the param
310308 - have access to form data without any validation
311309
312- ```
310+ ``` php
313311$form->noInterface(function($response){
314312
315313 if($response->has('amount')){
@@ -418,25 +416,25 @@ $form->isValidated();
418416## Old
419417- Takes a param as ` string ` and return old inserted data
420418 - Second parameter is [ optional] ` mixed data ` .
419+ - It's helper class can be called, using -- ` old() `
421420
422- ```
421+ ``` php
423422$form->rules([
424423 "s:password" => 'Please enter a name',
425424 "s:retype_pass:!==:{$form->old('password')}" => 'Password mismatch, Please enter same password',
426425]);
427426```
428427
429- - or -- ` Helpers Function `
430- ```
428+ - or
429+ ``` html
431430<input type =" email" name =" email" value =" <?= old('email', 'default_value')>" >
432431```
433432![ Sample Session Schema] ( https://raw.githubusercontent.com/tamedevelopers/validator/main/old.png )
434433
435-
436434## GetForm
437435- Return all submitted form data as an ` array `
438436
439- ```
437+ ``` php
440438->save(function($response){
441439
442440 $data = $response->getForm();
@@ -448,7 +446,7 @@ $form->rules([
448446 - Merge two array data together
449447 - Second data will always repalace any matched key data in the first array
450448
451- ```
449+ ``` php
452450->save(function($response){
453451
454452 $data = [
@@ -469,7 +467,7 @@ $form->rules([
469467| ----------| -----------------------------|
470468| ` array ` | Main data to select from |
471469
472- ```
470+ ``` php
473471->save(function($response){
474472
475473 $data = $response->onlyData(['email', 'password'], [
@@ -479,8 +477,7 @@ $form->rules([
479477 'password' => 'test',
480478 ]);
481479
482- ---
483- Only ['email', 'password'] will be returned.
480+ // Only ['email', 'password'] will be returned.
484481});
485482```
486483
@@ -491,7 +488,7 @@ $form->rules([
491488| -----------------| -----------------------------|
492489| Keys are array | Main data to select from |
493490
494- ```
491+ ``` php
495492->save(function($response){
496493
497494 $data = $response->exceptData(['_token'], [
@@ -500,8 +497,7 @@ $form->rules([
500497 'password' => 'test'
501498 ]);
502499
503- ---
504- Return all array element, except ['_token']
500+ // Return all array element, except ['_token']
505501});
506502```
507503
@@ -512,7 +508,7 @@ $form->rules([
512508| class | ` Class name ` Class name on error and success |
513509
514510
515- ```
511+ ``` php
516512$form->getMessage();
517513$form->getClass();
518514```
@@ -523,7 +519,7 @@ $form->getClass();
523519- Forms ` param ` returns a Collection Class
524520 - This enable us access property as an ` object ` or ` array index `
525521
526- ```
522+ ``` php
527523$form->rules([
528524 "string:country:==:0" => 'Please Select a Country',
529525 "email:email" => 'Please enter a valid email address',
@@ -535,9 +531,8 @@ $form->rules([
535531 $param->country;
536532 $param['country']
537533
538- ---
539- As you can see, we're able to access data in both ways without errors
540- })
534+ // As you can see, we're able to access data in both ways without errors
535+ });
541536```
542537
543538## Collection Methods
@@ -553,7 +548,7 @@ $form->rules([
553548- Takes a param as ` mixed ` data
554549 - Converts to an ` Object ` data
555550
556- ```
551+ ``` php
557552$form->toObject([
558553 'food' => 'Basmati Rice'
559554]);
@@ -563,7 +558,7 @@ $form->toObject([
563558- Takes a param as ` mixed ` data
564559 - Converts to an ` Array ` data
565560
566- ```
561+ ``` php
567562$form->toArray([
568563 'food' => 'Basmati Rice'
569564]);
@@ -573,7 +568,7 @@ $form->toArray([
573568- Takes a param as ` mixed ` data
574569 - Converts to an ` Json ` data
575570
576- ```
571+ ``` php
577572$form->toJson([
578573 'food' => 'Basmati Rice'
579574]);
0 commit comments