Support the ongoing development of Laravel.io →
Eloquent Forms Input
Last updated 1 year ago.
0

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

Last updated 6 years ago.
0

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!

0

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 '. , '~!@#$%^

Last updated 6 years ago.
0

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!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Chris iplayguitar81 Joined 25 Oct 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.