$form->rules([
"s:name" => 'Please enter a name',
])->validate(function($response){
$response->param; //Collection of form data
$response->getMessage(); //message property
});
Save
Expects a closure function as the param
Message property will be empty string on success $response->message
$form->rules([
"s:name" => 'Please enter a name',
])->save(function(){
//on success
});
Data Types
Supports 9 Data Flags type
Data types
abbr
Description
email
e
Email data validation
bool
b
Boolean data validation
string
s
String data validation
str_len
sl
String Length validation
enum
en
Enum Forms checkbox | radio or any form data that normally has no value when not checked
Will only execute code within when Request is [GET]
CSRF Token does'nt apply to this method
$form->rules([
"s:name" => 'Please enter a name',
])->before(function($response){
// execute code
});
After
Expects a closure function as the param
Will always execute no matter the request method type
CSRF Token does'nt apply to this method
$form->after(function(){
// execute code
});
Has Error
Returns bool true\|false
$form->hasError();
Is Validated
Returns bool true\|false, When Form has already been validated
$form->isValidated();
Reset Error
Even if you're inside the success() method
With this helper, you can be able to reset the class, to error class
->save(function($response){
$availableUserAmount = 900;
<!-- Lets say for instance, users have wallet balance and the form request has no error -->
<!-- But you need to perform another error validator before you allow request to pass through -->
<!-- Don't forget the add the "return;" key to stop any other code from executing -->
if($response->amount > $availableUserAmount){
$response->reset();
$response->message = "Your wallet balance is too low, Please recharge before you can Subscribe to Plan!";
return;
}
// perform other request before
});
Takes a param as string and return old inserted data
Second parameter is [optional] mixed data.
$form->rules([
"s:password" => 'Please enter a name',
"s:retype_pass:!==:{$form->old('password')}" => 'Password mismatch, Please enter same password',
]);
Message This convert all error messages and return as a string with <br>
class
Class name Class name on error and success
$form->getMessage();
$form->getClass();
Collection
Forms param returns a Collection Class
This enable us access property as an object or array index
$form->rules([
"string:country:==:0" => 'Please Select a Country',
"email:email" => 'Please enter a valid email address',
])->save(function($response){
$param = $response->param;
$param->country;
$param['country']
---
As you can see, we're able to access data in both ways without errors
})