【问题标题】:getting error while redirecting back to a page重定向回页面时出错
【发布时间】:2016-11-06 02:45:34
【问题描述】:

我有一个带有“电子邮件”字段的表单。如果电子邮件字段为空,那么我想重定向回与警报消息相同的表单。我试过代码

return Redirect::back()
                    ->withErrors($validator)
                    ->withInput();

它被重定向到所需的页面,但我在 RouteCollection.php 第 218 行收到 MethodNotAllowedHttpException: 这个错误。单击浏览器的后退按钮后,我会根据需要收到警报消息。如何解决?

【问题讨论】:

  • 我认为您收到该错误是因为您正在发布到 GET 路由。澄清Here
  • 我已经将 route.php 中的函数描述为: Route::get('dramareport', 'ReportsController@dramareport');路线::post('d_report', 'ReportsController@d_report');我参考了您显示的链接,但我不明白。
  • 您在哪个 url 中收到错误?是/dramareport 吗?
  • 你的表单action属性内容是什么?
  • {!! Form::open(['url' => 'send_mail', 'class' => 'form-horizo​​ntal','onsubmit'=>'myFunction()']) !!} 这就是我声明表单的方式

标签: php laravel


【解决方案1】:

你也可以像这样返回错误

return Redirect::to('/yout/path/here/')
                        ->withErrors($validator)
                        ->withInput();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    相关资源
    最近更新 更多