How to validate without empty other filled fields Laravel - laravel

Hi there I have this fields:
<form role="form" class="form margin-bottom-0" action="{{ url('/test') }}" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="box box-widget widget-use padding-40 padding-top-0 box-shadow-none">
<div class="row">
<div class="col-md-6">
<div class="form-group floating-label {{ $errors->has('name') ? ' has-error' : '' }}">
<input class="form-control" name="name" id="regular2" type="text" value="#if($account){{$account['name']}} #endif" >
<label for="regular2" >#lang('payment.full_name')</label>
#if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
</div>
<div class="col-md-6">
<div class="form-group floating-label {{ $errors->has('address') ? ' has-error' : '' }}">
<input class="form-control" name="address" id="regular2" type="text" value="#if($account){{$account['address']}}#endif" >
<label for="regular2">#lang('payment.address')</label>
#if ($errors->has('address'))
<span class="help-block">
<strong>{{ $errors->first('address') }}</strong>
</span>
#endif
</div>
</div>
</div>
</div>
<button type="submit" class="btn save-lang savecard">#lang('buttons.save_changes')</button>
</form>
and when I submit it shows me the validation just fine
but when I fill one field and I submit the field that I put text on it empties, how can I make the text to stay..?

Try this on every inputs you have:
<input class="form-control" name="name" id="regular2" type="text" value="{{ old('name') }}" >
Just use old().

You can use the old method in your template referring the documentation
If you use $this->validate(/*your rules*/) in your controller, it will send the errors and the old input.
Then your can use for exemple :
<input class="form-control" name="name" id="regular2" type="text" value="{{ old('name') }}" > To make the text stay.
Hopes it helps you.

Related

How to adjust card height with Bootstrap in Laravel 5

I am trying to follow this template design:Template and I seem to be having some issue regarding the card height and padding with my current login page. Here is the code:
#section('content')
<div class="container">
<div class="card row h-100">
<div class="card-body">
<form method="POST" action="{{ route('login') }}">
#csrf
<div class="row">
<div class="col">
<img class="img-fluid rounded mx-auto d-block" src="{{asset('svg/MegaDeskLogo.svg')}}" alt="logo" />
</div>
<div class="col">
<h1>{{ __('Login') }}</h1>
<input id="email" type="email" placeholder="{{ __('E-Mail Address') }}" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}"
name="email" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>
{{ $errors->first('email') }}
</strong>
</span>
#endif
<input id="password" placeholder="{{ __('Password') }}" type="password" class="form-control {{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
#if ($errors->has('password'))
<span class="invalid-feedback" role="alert">
<strong>
{{ $errors->first('password') }}
</strong>
</span>
#endif
<div class="form-check">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old( 'remember') ? 'checked' : '' }}>
<label class="form-check-label" for="remember">
{{ __('Remember Me') }}
</label>
</div>
<button type="submit" class="btn btn-primary">
{{ __('Login') }}
</button>
#if (Route::has('password.request'))
<a class="btn btn-link" href="{{route('password.request') }}">
{{ __('Forgot Your Password?') }}
</a>
#endif
</div>
</div>
</form>
</div>
</div>
</div>
#endsection
Currently it's looking like: . I've tried reading several articles and reading the bootstrap documentation and still not able to find the answer. If anyone can offer any suggestions I would really appreciate it.
Make sure you're adding all the CSS and Javascript libraries and code you need for your card to look like the example, they are using more than just bootstrap.
Their CSS block:
Their Script block looks like:

Laravel Auth not working after moving to remove

I have moved my local laravel Application to Production. On my local pc the register function work's well (using Laravel Auth). On the remote host nothing happeds when I submit the register form. No validation error or something else. What is wrong with my application?
I got an 404 while the process. Here my register routes:
Route::get('register', 'Auth\RegisterController#showRegistrationForm')->name('register');
Route::post('register', 'Auth\RegisterController#register');
Here the content of my register.blade.php file:
<form id="js-validation-signup" action="{{ route('register') }}" method="post">
#csrf
<div class="py-3">
<div class="form-group">
<input type="text"
class="form-control form-control-lg form-control-alt{{ $errors->has('first_name') ? ' is-invalid' : '' }}"
id="first_name" name="first_name" placeholder="{{ __('First Name') }}"
value="{{ old('first_name') }}" autocomplete="off">
#if ($errors->has('first_name'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('first_name') }}</strong>
</span>
#endif
</div>
<div class="form-group">
<input type="text"
class="form-control form-control-lg form-control-alt{{ $errors->has('name') ? ' is-invalid' : '' }}"
id="name" name="name" placeholder="{{ __('Name') }}"
value="{{ old('name') }}" autocomplete="off">
#if ($errors->has('name'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
<div class="form-group">
<input type="email"
class="form-control form-control-lg form-control-alt{{ $errors->has('email') ? ' is-invalid' : '' }}"
id="email" name="email" placeholder="{{ __('E-Mail Address') }}"
autocomplete="off" value="{{ old('email') }}">
#if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
<div class="form-group">
<input type="password"
class="form-control form-control-lg form-control-alt{{ $errors->has('password') ? ' is-invalid' : '' }}"
id="password" name="password" placeholder="{{ __('Password') }}">
#if ($errors->has('password'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
<div class="form-group">
<input type="password" class="form-control form-control-lg form-control-alt"
id="password_confirmation" name="password_confirmation"
placeholder="{{ __('Confirm Password') }}">
</div>
<div class="form-group">
<div class="input-group">
<input class="form-control form-control-lg form-control-alt{{ $errors->has('application_name') ? ' is-invalid' : '' }}"
id="application_name"
name="application_name" type="text"
placeholder="{{ __('Application Name') }}" autocomplete="off"
value="{{ old('application_name') }}">
<div class="input-group-append">
<span class="input-group-text input-group-text-alt">.example.com</span>
</div>
#if ($errors->has('application_name'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('application_name') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<div class="custom-control custom-checkbox custom-control-primary">
<input type="checkbox" class="custom-control-input" id="signup-terms"
name="signup-terms">
<label class="custom-control-label" for="signup-terms">I agree to Terms &
Conditions</label>
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-block btn-hero-lg btn-hero-primary">
<i class="fa fa-fw fa-user-plus mr-1"></i> Sign Up
</button>
<p class="mt-3 mb-0 d-lg-flex justify-content-lg-between">
<a class="btn btn-sm btn-light d-block d-lg-inline-block mb-1" href="#">
<i class="fa fa-book text-muted mr-1"></i> Read Terms
</a>
</p>
</div>
</form>
I think i had the same problem with login here.
my problem was that I used Laravel's auth login and inside Auth/LoginController has a
use AuthenticatesUsers which uses a trait that is inside vendor and Auth folder and when I wanted to use git clone to get the project on another computer and used composer install to install the used packages for the project my vendor changed to default and all the login code which was in AuthenticatesUsers trait removed and changed to default
The route() function is for named routes.
It seems that you named your get route but didn't do that with the corresponding post route. Accessing route('register') with a POST method will result in a 404 error.
Try to name the post route as well or use action('Auth\RegisterController#register')
<form id="js-validation-signup" action="{{action('Auth\RegisterController#register')}}" method="post">

Catch ONLY the invalid credentials error in a login.blade Laravel

I am using the custom login controller from Laravel. I have the validation messages in a below the input fields.
Everything works fine.
What I want now is to show a message “incorrect credentials” ONLY when user or password are incorrect and in a different div. I mean, if other validation error triggers, this message should not be visible.
The errors->has(‘email’) array catches this error but also the rest, for instance, ‘the field is required’.
Does anybody know how to write a condition that only catches this ‘invalid credentials’ error message?
Below the template.
Thanks in advance for your help!
#extends ('layouts.default')
#section('content')
#if ($errors->has('email')) {{-- I want the credential error here, but only
for credential error is triggered --}}
<div class="warning">
<div class="input-icon">
<i style="font-size:1.5em; color:Tomato; margin-right:5px;" class="fas
fa-exclamation-triangle"></i>
</div>
<p>Usuario o contraseña incorrecta</p>
</div>
#endif
<main class="login-page">
<div class="contact login">
<div class="titulos">
<p>Ingresar</p>
<p>Soy nuevo</p>
</div>
<form method="post">
#csrf
<div class="input-group input-group-icon">
<input type="email" name="email" placeholder="Correo electrónico"
value="{{ old('email') }}" autofocus/>
<div class="input-icon">
<i class="fas fa-envelope"></i>
</div>
<span class="obligatorio" > {{ $errors->first('email') }}</span>
</div>
<div class="input-group input-group-icon">
<input type="password" name="contraseña"
placeholder="Contraseña"/>
<div class="input-icon">
<i class="fas fa-lock"></i>
</div>
<span class="obligatorio" >{{ $errors->first('contraseña') }}
<div class="input-group">
<input type="submit" value="Ingresar" />
<a href="{{ route('password.request') }}">Olvidé mi
contraseña</a>
</div>
<div>
<label>
<input type="checkbox" name="recordar" id="cbox1"
value="recordar" {{ old('recordar') ? 'checked' : '' }}>
<span>Recordar mi usuario</span>
</label>
</div>
</form>
</div>
</main>
#endsection
In an old beginner Project of mine I did it this way:
<div class="form-group{{ $errors->has('text') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">#lang('views/auth/login.username')</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name">
#if ($errors->has('text'))
<span class="help-block">
<strong>{{ $errors->first('text') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">#lang('views/auth/login.password')</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password">
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
And inside the Controller I just catched the Exceptions:
public function authenticate(Request $request)
{
try {
$this->ldapHelper->checkCredentials($request->name, $request->password);
$ldapUserData = $this->ldapHelper->getFormattedUserData(request('name'));
$this->sessionService->login($ldapUserData);
return redirect()->route('form.formular');
} catch (\Exception $e) {
return back()->withInput()->withErrors([
'message' => $e->getMessage(),
]);
}
}
Maybe it helps!

how login/register from any page in laravel

I'm using Laravel 5.5 and I want to login/register from any page in my application and not to be require to load domain.com/login or domain.com/register for that.
PS: I'm using default authentication php artisan make:auth
Just copy the form content of login/Register page and paste it in your laravel page.
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : ''}}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a class="btn btn-link" href="{{ url('/password/reset') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>

Laravel : How to show form error feedback of input that `type='file'`?

I am using Laravel 5.5 and bootstrap 4.0-beta .
How to show form error feedback of input that type='file'?
If input type='text',I can show error feedback like this:
<div class="form-group row">
<label for="username" class="col-2 col-form-label">username:</label>
<div class="col-10">
<input id="username" name="username" class="form-control {{ $errors->has('username') ? ' is-invalid' : '' }}" type="text" value="{{ old('username') }}">
#if ($errors->has('username'))
<div class="invalid-feedback">{{ $errors->first('username') }}</div>
#endif
</div>
</div>
question:
If input type='file', how to show error feedback? The code below does not work.
<div class="form-group row">
<label for="photo" class="col-2 col-form-label">photo:</label>
<div class="col-10">
<input type="file" id="photo" name="photo">
#if ($errors->has('photo'))
<div class="invalid-feedback">{{ $errors->first('photo') }}</div>
#endif
</div>
</div>
Try adding is-invalid class to the input.
<div class="form-group row">
<label for="photo" class="col-2 col-form-label">photo:</label>
<div class="col-10">
<input type="file" id="photo" name="photo" class="form-control {{ $errors->has('photo') ? ' is-invalid' : '' }}">
#if ($errors->has('photo'))
<div class="invalid-feedback">{{ $errors->first('photo') }}</div>
#endif
</div>
</div>

Resources