简体   繁体   English

Laravel表单提交问题

[英]Laravel form submission issues

I have tried to resolve this before posting and I know this is a simple question but I'm still having trouble. 在发布之前,我已经尝试解决此问题,并且我知道这是一个简单的问题,但仍然遇到问题。

I've created a form that submits terms using a post and then attempting to run a route that calls a function within a controller which then redirects the user to the correct page using the previously submitted term. 我创建了一个表单,该表单使用帖子提交术语,然后尝试运行在控制器中调用函数的路由,然后该控制器使用先前提交的术语将用户重定向到正确的页面。 What is happening is i"m being redirected to a page has expired. 发生了什么事,我被重定向到页面已过期。

If there is a better way to do this I'm up for trying that to. 如果有更好的方法可以做到这一点,我将尝试这样做。

Here is the code. 这是代码。

<form action="/search" method="post" class="form-inline justify-content-center">
<input type="text" name="term" size="40" id="search">
<input type="submit" value="Submit">
</form> 

Web route 网络路线

Route::post('/search', 'MovieSearchController@search')->name('searchResults');

Controller - atm i'm testing to see if this is being called, which it is not. 控制器-atm我正在测试以查看是否正在调用它,不是。

public function search(ServerRequestInterface $request)
{
    $term = 'potatos';
    return redirect('/search/' . $term);
}

From what i see your form does not have a CSRF token field. 从我看来,您的表单没有CSRF令牌字段。

Add one by using {{ csrf_field() }} 使用{{ csrf_field() }}添加一个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM