Php HTML5表单搜索输入和干净的URL查询?
我有一个搜索输入表单Php HTML5表单搜索输入和干净的URL查询?,php,html,laravel,octobercms,Php,Html,Laravel,Octobercms,我有一个搜索输入表单 <form action="/search"> <input type="search" name="tags"> <button type="submit">Search</button> </form> 如何使其生成干净的URL localhost:8888/search/galaxy/ 对于带分隔符的多个关键字 localhost:8888/search?tags=galaxy+stars
<form action="/search">
<input type="search" name="tags">
<button type="submit">Search</button>
</form>
如何使其生成干净的URL
localhost:8888/search/galaxy/
对于带分隔符的多个关键字
localhost:8888/search?tags=galaxy+stars+space
localhost:8888/search?tags=galaxy%2C+stars%2C+space
这样我就不需要解析查询,因为我的CMS已经使用了干净的URL,它将重定向到正确的结果。它不必是type=“search”,任何可以根据用户输入重定向到干净url的输入。这里有几个选项 1-将数据发布到服务器,不显示URL,然后服务器返回一个干净的URL
public function search(Request $request)
{
$tags = $request->tags;
return redirect()->to('search/' . $tags); //I assumed only one tag was passed
}
由此,您可以向用户显示干净的URL。并在有多个标记时添加额外的logique
2-在提交时使用Javascriptonclick
重写URL
<input type="search" name="tags">
<input type="submit" onclick="window.location.href=this.form.action + this.form.q.value;" />
<!--/search/tags-->
您是否在OctoberCMS中使用任何框架???@EhsanIlahi Laravel。您可能需要执行以下操作:除非我误解了您的问题。因为表单操作在呈现页面后是静态的,如果不使用客户端编程,就无法真正更改。因为表单操作决定了客户端导航到的URL。@EhsanIlahi我希望尽可能不使用javascript或jQuery。我只需要在按下提交按钮时重定向到/search/{users input}的输入。我需要它清理URL,因为分页无法使用传统的查询字符串处理我的CMS。
<input type="search" name="tags">
<input type="submit" onclick="window.location.href=this.form.action + this.form.q.value;" />
<!--/search/tags-->