Skip to content

Commit f275a19

Browse files
author
Fredrick Peter
committed
added CSRF Token per request
1 parent 767efcc commit f275a19

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* [Csrf Token](#csrf-token)
2020
* [Usage](#usage)
2121
* [Error Type](#error-type)
22+
* [Token](#token)
2223
* [POST](#post)
2324
* [GET](#get)
2425
* [ALL](#all)
@@ -59,7 +60,7 @@ Prior to installing `ultimate-uploader` get the [Composer](https://getcomposer.o
5960
**Step 1** — update your `composer.json`:
6061
```composer.json
6162
"require": {
62-
"peterson/php-form-validator": "^3.3.1"
63+
"peterson/php-form-validator": "^3.3.2"
6364
}
6465
```
6566

@@ -119,11 +120,12 @@ public function save(Request $request){
119120
- All are Optional `method`
120121
- These methods are only mandatory on usage and should always come first before others.
121122

122-
| Methods | Description |
123-
|----------|-------------------------------|
124-
| ->et() | Takes param as `bool` to format error's on display: `single or multiple` |
125-
| ->post() | No param needed. SET `form` request to `POST` only |
126-
| ->get() | No param needed. SET `form` request to `GET` only |
123+
| Methods | Description |
124+
|-----------|-------------------------------|
125+
| ->et() | Takes param as `bool` to format error's on display: `single or multiple` |
126+
| ->token() | Takes param as `bool` to Enable or Disable `csrf_token` for each request |
127+
| ->post() | No param needed. SET `form` request to `POST` only |
128+
| ->get() | No param needed. SET `form` request to `GET` only |
127129

128130
```
129131
$form->post()->submit([
@@ -199,6 +201,28 @@ $form->et(true)->submit([
199201
])
200202
```
201203

204+
### Token
205+
- Takes a param as `bool` Default is `false`
206+
- Allow disability of `csrf_token` on each form request
207+
208+
| Error | Description |
209+
|-------|-------------------------------|
210+
| false | `Default` Will disable `csrf_token` usage |
211+
| true | This allow `csrf_token` per request only |
212+
213+
```
214+
$form->token(false);
215+
```
216+
217+
- or
218+
219+
```
220+
$form->token(true)->submit([
221+
"string:country:==:0" => 'Please Select a Country',
222+
"email:email" => 'Please enter a valid email address',
223+
])
224+
```
225+
202226
### POST
203227
- You can call separately or Call Before any other method, if intend to use.
204228
- This will set the Form Request to `POST`

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"extra": {
3636
"branch-alias": {
37-
"dev-main": "3.3.1-dev"
37+
"dev-main": "3.3.2-dev"
3838
}
3939
},
4040
"minimum-stability": "stable",

src/Traits/ValidatorTrait.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ public function et(?bool $type = false)
9595
return $this;
9696
}
9797

98+
/**
99+
* CSRF Token
100+
* @param bool $type\ Token type
101+
* - true|false \Default is false
102+
*
103+
* @return object
104+
*/
105+
public function token(?bool $type = false)
106+
{
107+
$this->allow_csrf = $type;
108+
109+
return $this;
110+
}
111+
98112
/**
99113
* Set Request to POST
100114
*

0 commit comments

Comments
 (0)