laravel使用会话存储输入字段并传递到另一个页面 [英] laravel use session to store input field and pass to another page
问题描述
我是laravel的新手,我有带输入字段的表单,但我想发送输入值并在其他页面中使用会话显示,以便以后检查它们 请回答代码
Im new in laravel I have form with input fields but I want to send the input values and dispaly in other page using session to check them later Please answer with code please
表格:
<form id="booking-form">
<input class="indexinput" type="text" id="country" name="country"
placeholder="Country">
<input class="indexinput" type="text" id="state" name="state"
placeholder="State">
<input class="indexinput" type="text" id="city" name="city" placeholder="city">
</form>
<button class="button getbids" >GET BIDS</button>
<script type="text/javascript">
$(document).on('click', '.getbids', function() {
var loggedIn = {{ auth()->check() ? 'true' : 'false' }};
if (loggedIn)
window.location.replace('customer/dashboard');
if(!loggedIn)
$('#loginModal').modal('show');
});
</script>
路线
Route::group(['middleware'=>['rolecustomer']], function () {
Route::get('/customer/dashboard', 'HomeController@index')->name('customer.dashboard');
});
控制器:
public function index()
{
return view('index.customer.customerdashboard');
}
推荐答案
通过查看您的代码,我了解到您在单击提交"按钮后正在尝试检查用户是否已通过身份验证.如果他已通过身份验证,则将其重定向到customer/dashboard
.如果未通过身份验证,则显示的是登录模式.
By looking at your code, i understand that you are trying to check whether a user is authenticated after clicking the submit button. If he is authenticated, you are redirecting him to customer/dashboard
. If he is not authenticated, you are displaying a login modal.
问题是您正在使用javascript将用户重定向到页面,但无法获取使用表单提交的数据.所以我想您正在尝试使用session
来获取customer/dashboard
中的表单数据.您可以像下面这样简单地实现所需的方式.
The problem is you are redirecting the user to a page using javascript and you can't get the data submitted using the form. So i guess you are trying to use session
to get the form data in customer/dashboard
. you can achieve what you want way simply like below.
<form id="booking-form" method="POST" action="{{ route('customer.dashboard') }}">
将您的JavaScript代码更改为
change your javascript code to
<script type="text/javascript">
$(document).on('click', '.getbids', function() {
var loggedIn = {{ auth()->check() ? 'true' : 'false' }};
if (loggedIn)
$('#booking-form').submit();
if(!loggedIn)
$('#loginModal').modal('show');
});
</script>
现在将您的路线设置为
Route::any('/customer/dashboard', 'HomeController@index')->name('customer.dashboard');
这篇关于laravel使用会话存储输入字段并传递到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!