【问题标题】:Laravel issue with route and HTML form action路由和 HTML 表单操作的 Laravel 问题
【发布时间】:2017-07-08 05:54:01
【问题描述】:

我的表单出现问题,在提交时我收到错误消息“哎呀,好像出了点问题。”。

我正在使用 Laravel 4.2,我的路线如下所示:

Route::get('/', function()
{
    return View::make('index');
});

Route::post('/', array('as' => 'login', 'uses' => 'HomeController@login'));

我的表格是这样的:

<form action="{{ action('HomeController@login') }}" method="post">
     <input class="signUpField-index" id="signUpEmail-index" type="text" placeholder="Email Address (required, but never shown) *" name="email" />
     <input class="signUpField-index" id="signUpPassword-index" type="password" placeholder="Password *" name="password" />
     <input id="signUpSubmit-index" type="submit" value="Sign Up" />
     <input name="_token" type="hidden" value="{{ csrf_token() }}"/>
</form>

我的控制器看起来像这样:

<?php

class HomeController extends BaseController {

public function showIndex()
{
    return View::make('index');
}

public function login() {
    //return var_dump(_POST);
    return View::make('index');
}
}

我认为这可能是不正确的操作,但我不太确定,我尝试查看其他示例和教程,例如:Adding form action in html in laravel,但它们没有帮助。

提前致谢。

【问题讨论】:

    标签: php forms laravel


    【解决方案1】:

    不是action,而是url。 使用:

    <form url="your action" method="post">
    
    </form>
    

    但是如果你想留在同一个页面上,请使用 Ajax 进行提交。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-22
      • 2020-10-24
      • 1970-01-01
      • 2015-11-24
      • 2019-12-04
      • 1970-01-01
      • 2014-02-28
      相关资源
      最近更新 更多