【问题标题】:Laravel 5 Form Submit to ViewLaravel 5 表单提交查看
【发布时间】:2017-04-18 03:03:52
【问题描述】:

我正在重新编写我的网站并转移到 Laravel,但由于某种原因,我无法弄清楚如何使用搜索表单将您重定向到个人资料页面。

<form class="navbar-form navbar-right search" role="search" action="/profile/" method="GET">
<div class="input-group">
<input type="text" class="form-control navbar-player-search" placeholder="Enter IGN here" autocomplete="off" required>
        <div class="input-group-btn">
            <button type="submit" class="btn btn-default">
                <i class="glyphicon glyphicon-search"></i>
            </button>
        </div>
    </div>
</form>

如果我访问 example.com/profile/Callahan,我已经设置了一条有效的路线

Route::get('/profile/{Profile}', 'PlayerController@getStats');

但我需要表格来做同样的事情。 是否可以使用默认的 laravel 5.4.3 来做到这一点,或者我需要像 https://laravelcollective.com/docs/5.3/html 这样的东西吗?

【问题讨论】:

    标签: php laravel laravel-5


    【解决方案1】:

    我不完全理解输入包含的信息,但我会考虑这个:

    用户将在输入中写入并单击搜索。 然后,在您的控制器中,您将在搜索后获得配置文件名称并重定向到配置文件。是这样吗?

    如果是,你应该这样做:

    路由

    Route::get('/profile/{Profile}', 'PlayerController@getStats');
    Route::get('/search', 'PlayerController@searchForm');
    Route::post('/search', 'PlayerController@search');
    

    控制器

    public function searchForm() {
        return view('search');
    }
    
    public function search(Request $request) {
        // get the input
        $inputText = ...;
        // logic to get the profile name
        $profileName = ...;
        return redirect('/profile/'.$profileName);
    }
    

    查看

    <form class="navbar-form navbar-right search" role="search" action="/search" method="POST">
    <div class="input-group">
    <input type="text" class="form-control navbar-player-search" placeholder="Enter IGN here" autocomplete="off" required>
            <div class="input-group-btn">
                <button type="submit" class="btn btn-default">
                    <i class="glyphicon glyphicon-search"></i>
                </button>
            </div>
        </div>
    </form>
    

    再说一次,我不知道这是否是您真正想要的,但如果不是,请告诉我再次尝试帮助您。

    【讨论】:

    • 公共函数 searchForm() { return view('search'); } 那需要是刀片视图吗?
    • 我在顶部的导航栏中有 html 搜索条码,在旧网站上,我只需将帖子数据提交到页面,然后检查是否发送了帖子数据并将它们重定向到那里
    • 不需要使用刀片。该文件可能只是 .php 并且可以正常工作。对,所以这些代码对你有用吗?
    • 添加返回 MethodNotAllowedHttpException :(
    • POST 之后?您可以编辑问题以粘贴错误或打印吗?方法搜索中还有另一个代码?我需要看到更多内容来帮助你。
    猜你喜欢
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 2020-06-22
    • 1970-01-01
    相关资源
    最近更新 更多