Input.postAll
Input.postAll($mapOfFieldRules)
Description
Return multiple POST params sent in the current request (e.g. via a form or Ajax).
Each field will be validated per the rules defined in $mapOfFieldRules
. (See Input Validation)
The function will return a Map with the following fields:
-
ok
.true
if all fields passed validation. -
fields
. A map of all fields and their validated values. -
errors
. A list of all invalid fields.
SecurityPost requests must come from the same origin and contain a hidden
csrfToken
field, which you can get via Web.csrfToken()
. Use Input.remote
if you wish to accept requests without these safeguards.// post data: { userId: 12345, age: 39 } $data = Input.postAll({ userId: 'id', age: 'i|min:1|max:130', }); //= 12345 if $data.ok { print($data.fields); } // { // userId: 12345, // age: 39 // }
Invalid Data
If a field is invalid, its value will be returned as an empty string ''
and will be listed in the errors
List.
// Example of invalid field // post data: { userId: 12345, age: -100 } $data = Input.postAll({ userId: 'id', age: 'i|min:1|max:130', }); print($data.fields.age); //= '' (cleared) if !$data.ok { print($data.errors); } // [ // { // field: 'age', // error: 'must be greater than 1', // } // ],