【问题标题】:How to write form action in html/php code in laravel?如何在 laravel 的 html/php 代码中编写表单动作?
【发布时间】:2019-01-18 23:59:30
【问题描述】:

我正在对 HTML 表单进行实时搜索,其中如果我输入 La,所有内容都应显示与 La 相关。例如:拉曼、拉发等

我使用的 HTML 代码是:

<form autocomplete="off" id="search_form" method="GET" action="/search/helloWorld/{chars}">
   <div  style="padding-top:18%;margin-left:auto; margin-right:auto;">
      <!--           
         <div class="dates">
           <div class="start_date" style="width:50%;margin-right:3%;">
              <input readonly="readonly" class="form-control start_date  mb-4" type="text" placeholder="start date" id="startdate_datepicker">
           </div>
           <div class="end_date" style="width:50%;margin-left:3%;">
              <input readonly="readonly" class="form-control  end_date  mb-4" type="text" placeholder="end date" id="enddate_datepicker">
           </div>
         </div>
         -->
      <button type="submit" class="btn btn-default start_search_button" style="padding-left:12%;padding-right:12%;background-color: rgb(247, 144, 99);" >start search</button>
   </div>
</form>

我为 routes.php 文件做的路由是:

//helloworld routes
Route::get('search/helloWorld/{chars}','SearchController@helloWorld');


问题陈述:

我想知道我是否在上面的html代码中以正确的方式编写了action="/search/helloWorld/{chars}"&gt;。我们是否通过查看 Laravel (5) 中的路线来编写表单动作?

【问题讨论】:

  • 您能具体说明一下您当前的 laravel 版本吗? 5.1 或 5.2 或 .. 别的东西
  • @Thamerbelfkih Laravel 5.4 我是否以正确的方式完成了路由?
  • 我会写给你我的回复。请编辑您的问题,因为在 laravel 5.4 中我们没有 routes.php 而我们有 web.php
  • @Thamerbelfkih 我正在使用 routes.php 我感觉我告诉你错误的版本。我会再检查一遍
  • 请在 composer.json 文件中找到正确的版本

标签: laravel-5 controller routes action livesearch


【解决方案1】:

如果你使用的是 laravel 5.4,试试这个: 为您的路线添加名称以便于映射,如下所示:

Route::get ('/search/helloworld/{id}', Controller@method)->name ('search');

然后在您的表单中,将您的操作映射到路线的名称;

<form action="{{ route ('search', $char->id) }}">

等等。

请将我的 $char->Id 替换为您的真实参数

抱歉,我是在手机上发送的。希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2018-03-31
    • 2018-01-09
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-22
    • 2016-11-24
    • 1970-01-01
    相关资源
    最近更新 更多