在laravel的html中添加表单动作 [英] Adding form action in html in laravel
问题描述
< form method =postaction = ??这里写什么??接收字符集= UTF-8 >
我想将其操作设置为 WelcomeController @ log_in
在函数 WelcomeController
控制器中的文件。
这是我的路线:
路线:: get('/','WelcomeController @ home');
Route :: post('/',array('as'=>'log_in','uses'=>'WelcomeController @ log_in'));
Route :: get('home','HomeController @ index');
提交后,它保持相同的网址
http:// localhost:8000 /
错误行
哎呀,貌似出了问题。
之后在compiled.php第2440行中有 1/1 TokenMismatchException:
动作()$ c $ < form method =postaction ={{action( 'WelcomeController @ log_in')}}accept-charset =UTF-8>
请注意,Laravel 5默认安装已为整个身份验证过程提供了视图和控制器。只需在全新安装中转到 / home
,您应该将其重定向到登录页面。
另请确保阅读文档中的身份验证部分
< hr>
你现在得到的错误( TokenMismatchException
)是因为Laravel有开箱即用的CSRF保护功能
使用它并使错误消失)添加隐藏字段到您的表单:
< input name =_ tokentype =隐藏value ={{csrf_token()}}/>
或者,您也可以通过移除'App \Http\\从 $中间件
数组中的 app / Http / Kernel.php $ c $>中创建\\ Middleware \VerifyCsrfToken
c>
I am unable to pass url in views html form action tag.
<form method="post" action="??what to write here??" accept-charset="UTF-8">
I want to set it's action to WelcomeController@log_in
function in WelcomeController
file in controllers.
Here are my routes:
Route::get('/','WelcomeController@home');
Route::post('/', array('as' => 'log_in', 'uses' => 'WelcomeController@log_in'));
Route::get('home', 'HomeController@index');
After submitting it keeps the same url
http://localhost:8000/
And the main error line
Whoops, looks like something went wrong.
After that there is 1/1 TokenMismatchException in compiled.php line 2440:
解决方案 You can use the action()
helper to generate an URL to your route:
<form method="post" action="{{ action('WelcomeController@log_in') }}" accept-charset="UTF-8">
Note that the Laravel 5 default installation already comes with views and controllers for the whole authentication process. Just go to /home
on a fresh install and you should get redirected to a login page.
Also make sure to read the Authentication section in the docs
The error you're getting now (TokenMismatchException
) is because Laravel has CSRF protection out of the box
To make use of it (and make the error go away) add a hidden field to your form:
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
Alternatively you can also disable CSRF protection by removing 'App\Http\Middleware\VerifyCsrfToken'
from the $middleware
array in app/Http/Kernel.php
这篇关于在laravel的html中添加表单动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!