Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MoSalem's avatar

Can't displaying error messages in Registration form (Laravel UI)

Hello

I use Laravel UI for authentication in my project , i have issue when display validation error message build in Laravel Ui

the register form page is :

@extends('back.admins.layouts.app')

@section('content')

            <div class="card-body">
                <form method="POST" action="{{ route('admin/dashboard/store') }}">
                    @csrf
                    <div class="row mb-3">
                        <label for="name" class="col-md-4 col-form-label text-md-end">{{ __('Name') }}</label>

                        <div class="col-md-6">
                            <input id="name" type="text" class="form-control
                            @error('name') is-invalid @enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>

                            @error('name')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="row mb-3">
                        <label for="email" class="col-md-4 col-form-label text-md-end">{{ __('Email Address') }}</label>

                        <div class="col-md-6">
                            <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email">

                            @error('email')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>


                    <div class="row mb-3">
                        <label for="password" class="col-md-4 col-form-label text-md-end">{{ __('Password') }}</label>

                        <div class="col-md-6">
                            <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="new-password">

                            @error('password')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="row mb-3">
                        <label for="password-confirm" class="col-md-4 col-form-label text-md-end">{{ __('Confirm Password') }}</label>

                        <div class="col-md-6">
                            <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
                        </div>
                    </div>

                    <div class="row mb-0">
                        <div class="col-md-6 offset-md-4">
                            <button type="submit" class="btn btn-primary">
                                {{ __('Register') }}
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

and the store function in controller is :

public function store(Request $request){

$request->validate([

'name'=>['required' , 'string' , 'unique:admins,name'], 'email'=>['required' , 'string' , 'unique:admins,email' , 'email'], 'password'=>['required' , 'string','confirmed' , 'min:3' , 'max:10'], 'password_confirmation'=>['required' , 'string'], 'admin_key'=>['required' , 'string']

]);

return redirect()->back()->with('success' , 'register is done');

}
0 likes
14 replies
Snapey's avatar

do your old values get pushed back to the form?

MoSalem's avatar

@Snapey if i do dd($request->all()); i can see all values but when i tried to enter wrong values for validation , it not print error messages

MoSalem's avatar

@Snapey sorry if it case of my bad English . Could you please specify which values you mean?

Snapey's avatar

@MoSalem if you break validation, are you sent back to the form and does it contain the values you submitted

MoSalem's avatar

@Snapey no , i got message from browser itself that i must fill correct values , except for the password and its repetition, an error message appears in form " The password field confirmation does not match. "

Snapey's avatar

@MoSalem

The password field confirmation does not match

this message can only come from laravel. The browser does not know it should be comparing these fields. So your validation IS working, but there is something wrong with the way you validate or what you expect.

And you still have not answered if your form is filled with your previous submission

gych's avatar

Change the id of your password confirmation input field you are currently using password-confirm as id while it should be password_confirmation

 <input id="password_confirmation" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
MoSalem's avatar

@gych my issue that when enter invalid values for example when user type incorrect email format or enter password less than 3 digit ..etc , the $message in register form not print in form

gych's avatar

@MoSalem Can you test if it works when you display the error without the invalid-feedback class

@error('name')
	<span role="alert">
		<strong>{{ $message }}</strong>
	</span>
@enderror
Himmat's avatar

Please try with below code

Blade file

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ __('Register') }}</div>

                <div class="card-body">
                    <form method="POST" action="{{ route('register') }}">
                        @csrf

                        <div class="form-group row">
                            <label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>

                            <div class="col-md-6">
                                <input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>

                                @error('name')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email">

                                @error('email')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="new-password">

                                @error('password')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
                            </div>
                        </div>

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    {{ __('Register') }}
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

Controller

public function store(Request $request)
{
    // Validate the incoming request data
    $request->validate([
        'name' => ['required', 'string', 'unique:admins,name'],
        'email' => ['required', 'string', 'email', 'unique:admins,email'],
        'password' => ['required', 'string', 'confirmed', 'min:6'], // Minimum password length is set to 6, change if needed
    ]);

    // If validation passes, create a new admin record
    Admin::create([
        'name' => $request->name,
        'email' => $request->email,
        'password' => bcrypt($request->password), // Hash the password before storing it in the database
    ]);

    // Redirect back with a success message
    return redirect()->back()->with('success', 'Registration successful!');
}
MoSalem's avatar

@Himmat hi , sorry but after i change classes in form the result is same . no error message appear

MoSalem's avatar

OK guys , it solved by itself i don't change any class or any format and fount register message working in chrome and Firefox browsers

Please or to participate in this conversation.