you can use laravel form validation
use this inside ur controller
public function controllerName(Request $request){
$this->validate($request,[
'search'=>'required'
]);
}
you will automatically redirect()->back() if validation not satisfied. and automatic $request->flash() to re fill the previous form
you will get automatic $errors variable inside the view.blade.php to tell user if validation not satisfied
Thanks David! I forgot about simply just using the built in form validation since after all, it is a form! I appreciate that! I was wondering if it might be possible in the validation to prevent someone from typing something in particular into a form also. For example I would prefer if a user does not pass form validation if they input '. ' or '.'. Is this type of customization possible? Thank you for your help!
Hey Chris glad to help. yes you can with regular expression but u need to use array as the rule value instead of pipeline
$this->validate($request,[
'search'=>[
'required',
'regex:/^[\w]/'
]
]);
^[\w] = the first character of the line must be WORD or NUMBER,, no spaces no symbols like '. , '~!@#$%^
Wow thank you David that is exactly what I wanted to achieve! I tested it and it works great on my site! Thanks again for all your help!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community