Reputation: 2858
When I send the form, I'll get the page.
The page has expired due to inactivity.
Please refresh and try again.
How can I fix this so that when I click on the submit button I do not drop there and just update the page.
Secondly, and most importantly, after submitting the data in the form, I get an empty array, why? That is, after pressing the submit button, I drop it on the page I described at the top. The page has expired due to inactivity
. after backspace
if you press Ctrl+u then at the top of the page you can see this code.
Array
(
)
Why is the array empty? And please tell me how to fix it.
Here's my template contact.blade.php
@extends ("default.layouts.layout")
@section("content")
<div style="display: flex;">
<form method="post" action="{{ route ('contact') }}">
<label for="name">Name</label>
<input name="name" type="text" >
<label for="e-mail">E-mail adress</label>
<input name="e-mail" type="text">
<label for="site">Site</label>
<input name="site" type="text" style="margin-bottom: 10px;" >
<label for="text">Text</label>
<textarea name="text"></textarea>
<button style="background-color:lightslategrey" type="submit">Submit</button>
</form>
</div>
<style>
input {
display: flex;
}
</style>
@endsection
Here's my Controller ContactController
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ContactController extends Controller
{
public function show(Request $request){
print_r($request->all());
return view("default.contact",["title"=>"Contacts"]);
}
}
Also route web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get("/",["as"=>"home","uses"=>"Admin\IndexController@show"]);
Route::get("/about",["uses"=>"Admin\AboutController@show", "as"=>"about"]);
Route::match(["get","post"],"/contact",["uses"=>"Admin\ContactController@show","as"=>"contact"]);
Upvotes: 0
Views: 46
Reputation: 1998
One issue it that you have no CSRF token on your form. Laravel needs the CSRF token every time you perform a request otherwise it will just error out.
Add this to your form and see if it helps.
{{ csrf_field() }}
Upvotes: 0
Reputation: 2588
To fix the following error
The page has expired due to inactivity.
Please refresh and try again.
Add {{ csrf_field() }}
to your form
<form method="post" action="{{ route ('contact') }}">
{{ csrf_field() }}
...
</form>
Upvotes: 2