Laravel: cascading model login and registration using bootstrap - laravel

I am trying to make a cascaded login and registration model using bootstrap.
when I click on sign in button the model pop up which is fine but login field is not working. Registration button is working. Again click on Login button the fields appear. Here is the screenshots and code
<a href="#" class="nav-link" data-toggle="modal" data-target="#exampleModal">
<img src="public/img/sign-in-icon.png" class="img-sign-in img-responsive"></a></li>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<!-- Nav tabs -->
<ul class="nav nav-tabs md-tabs tabs-2">
<li class="active">
<a class="nav-link active" data-toggle="tab" href="#login-form" role="tab"><i class="fas fa-user mr-1"></i>
Login</a>
</li>
<li>
<a class="nav-link" data-toggle="tab" href="#registration-form" role="tab"><i class="fas fa-user-plus mr-1"></i>
Register</a>
</li>
</ul>
<!--
<li class="nav-item">
Register
</li> -->
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="tab-content">
<div id="login-form" class="tab-pane fade in active">
<form method="POST" action="{{ route('login') }}">
#csrf
<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" autofocus>
#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="current-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<div class="col-md-6 offset-md-4">
<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>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<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 id="registration-form" class="tab-pane fade">
<form action="/">
<div class="form-group">
<label for="name">Your Name:</label>
<input type="text" class="form-control" id="name" placeholder="Enter your name" name="name">
</div>
<div class="form-group">
<label for="newemail">Email:</label>
<input type="email" class="form-control" id="newemail" placeholder="Enter new email" name="newemail">
</div>
<div class="form-group">
<label for="newpwd">Password:</label>
<input type="password" class="form-control" id="newpwd" placeholder="New password" name="newpwd">
</div>
<button type="submit" class="btn btn-default">Register</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
Does anybody please know, what is wrong with the code?

Related

Modal form not send data to spring boot controller

I have a view made with bootstrap modal, but this form not send data to my controller. When print data from console I have only null values. My view is following:
modal-form
My code in the frontend is:
<!-- new modal -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<form th:action="#{/creconocida/addNew}" method="post">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h5 class="modal-title w-100" id="exampleModalLabel">Nueva
Comunidad Reconocida</h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Código
único</span>
</div>
<input type="text" class="form-control" id="codigo"
name="codigoN" aria-describedby="basic-addon3">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon2">Nombre</span>
</div>
<input type="text" class="form-control" id="nombre"
name="nombreN" aria-describedby="basic-addon3">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon3">Número
familias</span>
</div>
<input type="number" class="form-control" id="numero"
name="numeroN" aria-describedby="basic-addon3">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01">Nacionalidad</label>
</div>
<select class="custom-select" id="nacionalidad"
name="nacionalidadN">
<option selected>Seleccione...</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
</div>
<div class="modal-footer ">
<button type="submit" class="btn btn-primary mr-auto">Guardar</button>
<button type="button" class="btn btn-secondary"
data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</form>
</div>
Add new method in controller
#PostMapping("/addNew")
public String addNew(ComunidadReconocida creconocida) {
System.out.println("Guardando comunidad "+creconocida.getNam_m());//get only null values
asentamientoService.addNew(creconocida);
return "redirect:/creconocida/listar";
}
I can create a new entity but I can't send the values ​​entered in the form. How could I do to capture the values ​​and pass them to the controller
Your problem is you are not indicates to Spring that you want a '#RequestParam'.
public String addNew(#RequestParam ComunidadReconocida creconocida)

how to validate Unique database field on Controller in laravel

Good Day, I am new in Laravel environment. I am developing a simple school enrollment registration website but having trouble in validation on my controller..
My plan is, when the user will register in the website, username textbox should be validated if the username is already used by other student. i tried every possible tutorial i found in the net but i have no luck...
Here is my page, red circle should be validated if the input username already exist in the database..
Whole code in .blade
<!--Registration start here -->
<form method="Post" action="{{url('store_account_Registration')}}">
#csrf
#if(Session::get('success'))
<div class="alert alert-danger">
{{ Session::get('success')}}
</div>
#endif
#if(Session::get('fail'))
<div class="alert alert-danger">
{{ Session::get('fail')}}
</div>
#endif
<div class="col-sm-12 form-group">
<input type="hidden" class="form-control" name="uniqID3" id="uid" placeholder="Enrollment Registration Number" value="{{ $regid3 }}" >
</div>
<div class="col-sm-12 form-group">
<input type="hidden" class="form-control" name="pfulname3" id="name-f" placeholder="Enrollment Registration Number" required value="{{ $fulname4 }}" >
</div>
<div class="container-fluid" style="margin-bottom: 2em">
<div class="row justify-content-center align-items-center" style="padding: 10px">
<div class="card col-md-5" style="transform: none;>
<div class="card-body">
<div class="alert alert-primary" role="alert" style="margin-top: 1em">
<p>Name: <strong>{{ $fulname4 }}</strong></p>
<p>Enrollment No.: <strong>{{ $regid3 }}</strong></p>
</div>
<input type="hidden" class="hide" id="csrf_token" name="csrf_token" value="C8nPqbqTxzcML7Hw0jLRu41ry5b9a10a0e2bc2">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Username</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-user" aria-hidden="true"></i></span>
</div>
<input type="text" class="form-control" name="username" id="username" placeholder="Username" required value="{{ old('username')}}" >
</div>
<div class="help-block with-errors text-danger">
<span style="color:red">#error('username'){{ $message}}#enderror</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Password</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-lock" aria-hidden="true"></i></span>
</div>
<input type="password" id="password" name="password" pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Must have at least 6 characters' : ''); if(this.checkValidity()) form.password_two.pattern = this.value;" class="form-control" title="Password is needed" required placeholder="Password" >
</div>
<div class="help-block with-errors text-danger">
<span style="color:red">#error('password'){{ $message}}#enderror</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Confirm Password</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-lock" aria-hidden="true"></i></span>
</div>
<input id="password_two" type="password" name="password_two" pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Please enter the same Password as above' : '');" placeholder="Confirm Password" class="form-control" title="Confirm Password is needed" required placeholder="Confirm Password" >
</div>
<div class="help-block with-errors text-danger">
<span style="color:red">#error('password_two'){{ $message}}#enderror</span>
</div>
</div>
</div>
</div>
<div class="row" style="margin-top: 1em" >
<div class="col-md-12" style="margin-bottom: 2em">
<input type="hidden" name="redirect" value="">
<!-- <button type="submit" class="btn btn-primary btn-lg btn-block" name="submit">Save OASIS Account</button> -->
<!-- < <p class="btn btn-primary btn-lg btn-block">Save OASIS Account</p> -->
<button type="submit" class="btn btn-primary btn-lg btn-block">Save OASIS Account</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!--Registration start here -->
</div>
</form>
enter code here
I always got this error..
Here is my code..
my validation in my controller
public function store_account_Registration(Request $request)
{
request()->validate([
'username' => 'required|min:6|unique:TempAccount,AccountName,'
]);
// $this->validator($request->all())->validate();
$current_date = date('Y-m-d H:i:s');
$query = DB::table('TempAccount')->insert([
'RegID'=>$request->input('uniqID3'),
'FullName'=>$request->input('pfulname3'),
'AccountName'=>$request->input('username'),
'Pass'=>$request->input('password'),
'created_at'=> $current_date,
'updated_at'=> $current_date,
]);
if($query){
return back()->with('success', 'Data has been Successfyll inserted');
// return view('pages.enrollment_success');
// return redirect()->route('pages.enrollment_GradeLevelSchoolInfo', ['uniqIDd' => 1]);
// return redirect('enrollment_GradeLevelSchoolInfo');
}
else
{
return back()->with('fail', 'something went wrong');
}
}
my Route in web.php
Route::get('pages',[accountregistration::class, 'index']);
Route::Post('store_account_Registration', [accountregistration::class, 'store_account_Registration']);
my action in form..
The issue is in your form. You are not reaching the correct route at all.
Also you are missing the #csrf token or at least not shown in your print screen
<form action="{{url('store_account_Registration')}}" method="POST">
#csrf
In your validation you can remove the trailing coma after AccountName as well.

Redirect to registration bootstrap model in Laravel 6

I am using the following code in my controller for redirecting to login page if a guest user clicks button for uploading a product. Now I have created bootstrap model for login and registration. I want to pop-up the modal if user click button.
public function __construct()
{
$this->middleware('auth')->except('index', 'show');
}
Login and Register Button
#guest
<li class="list-inline-item">
<button type="button" class="btn btn-primary btn-outline-light" data-toggle="modal" data-target="#signIn" href="{{ route('login') }}">{{ __('Login') }}</button>
</li>
#if (Route::has('register'))
<li class="list-inline-item">
<button type="button" class="btn btn-primary btn-outline-light" data-toggle="modal" data-target="#signUp" href="{{ route('register') }}">{{ __('Register') }} </button>
</li>
#endif
Bootstrap Modal
<div class="modal" id="signIn">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">SignIn</h4>
<button type="button" class="close" data-dismiss="modal">
×
</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<form method="POST" action="{{ route('login') }}">
#csrf
<div class="form-group">
<label for="email" class="">{{ __('E-Mail Address') }}</label>
<input id="email" type="email" class="form-control" #error('email') is-invalid #enderror"
name="email" value="{{ old('email') }}" required autocomplete="email" autofocus />
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="form-group">
<label for="password" class="">{{ __('Password') }}</label>
<input id="password" type="password"
class="form-control #error('password') is-invalid #enderror" name="password" required
autocomplete="current-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">
Sign In
</button>
</div>
</form>
</div>
</div>
</div>
</div>

syntax error, unexpected 'layouts' (T_STRING), expecting ')' (View: C:\xampp7\htdocs\shopping\resources\views\auth\register.blade.php)

ican not open to page "register.blade.php" when I click to register itt alert this error
syntax error, unexpected 'layouts' (T_STRING), expecting ')' (View: C:\xampp7\htdocs\shopping\resources\views\auth\register.blade.php) I can open page login.blade.php
my code in app.blade.php::
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
#if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
#endif
There is a problem with your Register helper function, you are missing ')
<button type="submit" class="btn btn-primary">
{{ __('Register}}
</button>
Change to
<button type="submit" class="btn btn-primary">
{{ __('Register')}}
</button>
register.blade.php::
#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

How can I get it to validate my inputfield

The inputfield dosn't get validated it make a postrequest anyway wether or not the validations is valid
I have watched and followed serial youtube vidos, without any lock.
I have also tried to read the documentation but I couldn't find the error
MY Controller:
public function changepassword(Request $request)
{
$request->validate([
'passwordA' => 'string', 'min:8', 'same:passwordB',
'passwordB' => 'string', 'min:8',
]);
}
My view:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-header">Profil</div>
<div class="card-body">
<form method="POST" action="userprofile">
#csrf
<div class="form-group row">
<label for="username" class="col-sm-2 col-form-label">Username</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="username" placeholder="{{ $user->email }}" readonly>
</div>
</div>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" placeholder="{{ $user->firstname }} {{$user->surname}}" readonly>
</div>
</div>
<div class="form-group row">
<label for="phone" class="col-sm-2 col-form-label">Phonenumber</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="phone" placeholder="{{ $user->telephonenr }}" readonly>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
<label class="col-sm-12 col-form-label">Rest password</label>
</div>
</div>
<div class="form-group row">
<label for="passwordA" class="col-sm-2 col-form-label">New-Password</label>
<div class="col-sm-10">
<input type="password" class="form-control #error('passwordA') is-invalid #enderror" id="passwordA" name="PasswordA">
#error('passwordA')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="passwordB" class="col-sm-2 col-form-label">Type again</label>
<div class="col-sm-10">
<input type="password" class="form-control #error('passwordB') is-invalid #enderror" id="passwordB" name="PasswordB">
#error('passwordB')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<button type="submit" class="btn btn-primary">save</button>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
I was expected to validate the input and when I dosn't fit to the validating criteria the it should show the validation error

Resources