Laravel 419 Page Expired while submitting a form - php

While submitting a form on a pop-up modal the page gets expired on laravel, I am sending a post request.
Can someone please help? i have added a csrf token too..
View Blade
<div id="reviewModal-{{$ecgparticipant->getoriginal()['id']}}" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" >
</div>
<div class="modal-body">
<form id="ecgreviewform" class="ecgreview" action="{{ route('ecg.reviewstore') }}" method="POST">
#csrf
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="tesdt" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{auth()->user()->name}}">
</div>
</div>
<div class="modal-footer">
<div class="row">
<div class="col-md-6">
<button type="button" style = "width:50%;" class="btn btn-primary btn-outline-blue btn-close-modal" data-dismiss="modal">Cancel</button>
</div>
<input type="hidden" name="participant_id" value="{{$ecgparticipant->getoriginal()['id']}}">
<div class="col-md-6">
</div>
</div>
<button type="submit" form="ecgreviewform" style = "width:50%;" name="submit" value="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>
</div>
Route page
Route::get('ecg/pendingreview', 'EcgReviewController#index')->name('ecg.pendingreview');
Route::post('ecg/pendingreview', 'EcgReviewController#store')->name('ecg.reviewstore');
is there any reason

assign in your form 'method' like this:
<form method="post">
#csrf <!-- {{ csrf_field() }} -->
</form>
try with
{{ csrf_field() }}

Related

Authentication issue in laravel login form

I am trying to make a login form but it is not working and not giving any error.
my view:
Login
<!-- Login Modal -->
<div class="modal fade" id="LoginModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<form class="form" action="{{ url('/login') }}" role="form" method="POST" id="login-nav">
{{ csrf_field() }}
<div class="input-group">
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="input-group">
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="help-block text-center"><a target="_blank" href="#">Forget the password </a>
</div>
<div class="help-block text-right" id="add_err"></div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Signin</button>
</div>
<div class="checkbox">
<label> <input type="checkbox">Remember Me? </label>
</div>
</form>
</div>
</div>
</div>
my routes
Route::post('/login','LoginController#login');
my controller
public function login(Request $request)
{
if(Auth::guard('admin')->attempt($request->only('username','password'),$request->filled('remember'))){
//Authentication passed...
return redirect()
->intended(route('home'))
->with('status','You are Logged in as Admin!');
}
return ('failed');
//Authentication failed...
return $this->loginFailed();
}
when I run my code and submit login form it returns 'failed' which mean if condition not working in my controller so what's the reason behind this

Update field using laravel

When I try to update my lead_status it's not updating it's only redirecting to a page but can't update my lead status and when I return or dd($leads) it gives 0. why let me where I'm wrong and suggest me a solution
my update query
public function leadUpdate(Request $request)
{
$ids = $request->ids;
$lead_status = $request->lead_status;
$leads = DB::table('leads')
->where('id', $ids)
->update(['lead_status' => $lead_status]);
dd($leads);
return redirect('home/progress-leads')->with('success', 'lead accepted successfully');
}
my route is
Route::put('/home/accept-leads','HomeController#leadUpdate');
my blade form is
<form action="{{ url('home/accept-leads') }}" method="POST">
#csrf
#method('PUT')
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Accept Leads</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-12">
<h3>Are you sure to accept this lead</h3>
<div class="form-group">
<input type="checkbox" name="ids" value="{{ $leads->id }}">
<input type="hidden" class="form-control" name="lead_status">
</div>
</div>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button formaction="/home/accept-leads" type="submit" onclick="return myConfirm();" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</form>
Please help me...
Thanks in advance

How to open the modal if there is a validation error?

I have this code below, if a user is not authenticated it appears this "Login" link:
#if(!\Auth::check())
<span><a id="show_login_modal" href="javascript:void(0)">Login</a>
</span>
#endif
If the user logins with success the modal close and the user is loged in. Its working fine.
But if there is a validation error, for example if password is inscorrect, the modal is closed the user is not loged in and no error message appears. For the validaiton message appear is necessary to click in "login" to open again the modal and it apperas "These credentials do not match our records."
Do you know how to if there is a validation error open the modal without be necessary to click in "login"?
jQuery:
$('#show_login_modal').click(function(){
$('#login_modal').modal('show');
})
$('#close_login_modal').click(function(){
$('#login_modal').modal('hide');
})
Modal:
<div class="modal fade" id="login_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Login</h5>
<button type="button" class="close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="container">
<div class="row">
#include('includes.errors')
<form class="clearfix" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-group col-12 px-0">
<label for="inputEmail4">Email</label>
<input type="email" class="form-control" value="{{ old('email') }}" name="email" required autofocus placeholder="Email">
</div>
<div class="form-group col-12 px-0">
<label for="inputEmail4">Password
<a href="{{ route('password.request') }}" class="text-gray ml-1" style="text-decoration: underline">
<small>Recover password</small></a> </label>
<input type="password" class="form-control" name="password" required placeholder="Palavra-passe">
</div>
<button type="submit" class="btn btn-primary btn d-block w-100">Login</button>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" id="close_login_modal" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
errors.blade.php
#if ($errors->any())
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
#endif

Bootstrap - Modal's submit button not working

I've tried this but still the submit button won't work. I've recycled my code from the previous PHP I've worked but this time it isn't working, it just redirect me to my index.php page.
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form method="post" id="form1" action="actions/add_lab_test.php" class="form-horizontal row-border">
<div class="modal-body">
<h4>Add lab test</h4>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Result</label>
<div class="col-sm-6">
<textarea class="form-control autosize" name="c" id="c"></textarea>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">HIDDEN ID</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="a" id="a" value="<?php echo $a; ?>">
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
I've took the advice of wrapping the form from the content/body but still no luck, it isn't proceeding to the designated action.
Here is the button to trigger the modal
<div class="col-sm-2">
<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">Add Lab Test</a>
</div>
Even if I remove the <form></form> tags it still redirecting to the index.php

Modal Window Not Showing Up But Background Fades out

Here's the button that brings up the modal:
<li>Practice Schedule</li>
When I hit Practice Schedule button, the background fades out but the modal window does not show up.
Here's the modal code. Can you please see whats wrong with my code here?
<!-- Modal Practice Schedule Block Begin -->
<div class="modal" id="PrctcSched" tabindex="-1" role="dialog" aria-labelledby="lblPrctcHdr" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="lblPrctcHdr">
My Availability
</h4>
</div>
<!-- Modal Body Block Begin -->
<div class="modal-body">
<form class="form-horizontal" role="form" action="#" method="POST">
<div class="form-group">
<div class="col-sm-10">
<input type="checkbox" class="form-control" name="chbxDt1" Id="chbxDt1" value="chbxDt1chkd" class="col-sm-2 control-label">
<label for="chbxDt1">1</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="checkbox" class="form-control" name="chbxDt2" Id="chbxDt2" value="chbxDt2chkd" class="col-sm-2 control-label">
<label for="chbxDt2">2</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="checkbox" class="form-control" name="chbxDt3" Id="chbxDt3" value="chbxDt3chkd" class="col-sm-2 control-label">
<label for="chbxDt3">3</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Update My Availability</button>
</div>
</div>
</form>
<!-- Modal Footer -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"> Close </button>
</div>
</div>
<!-- Modal Body Block End -->
</div>
</div>
</div>
I just put your code into a page i am working on and it works fine. you can add the "fade" class to it to ensure that the modal fades in rather than just appearing, but the link triggered the modal for me.
<div class="modal fade" id="PrctcSched"...
Check your version of bootstrap and ensure that you have jquery,bootstrap.js AND bootstrap.css in your document head.

Categories