2017-02-24 46 views
0

我有一個搜索輸入表單。HTML5表單搜索用乾淨的URL查詢輸入?

<form action="/search"> 
    <input type="search" name="tags"> 
    <button type="submit">Search</button> 
</form> 

它會產生這樣的

localhost:8888/search?tags=galaxy 

一個網址我怎樣才能使它產生清潔的url

localhost:8888/search/galaxy/ 

並與separaters

localhost:8888/search?tags=galaxy+stars+space 

localhost:8888/search?tags=galaxy%2C+stars%2C+space 

這樣多個關鍵字我不需要解析q uery,因爲我的CMS已經使用乾淨的URL,它將重定向到正確的結果。它不必是type =「search」,任何可以根據用戶輸入重定向到乾淨網址的輸入。

+0

你使用任何框架的URL? –

+0

@EhsanIlahi Laravel與OctoberCMS。 –

+0

您可能需要執行以下操作:http://stackoverflow.com/a/39849708/1144627除非我誤解了您的問題。由於表單操作在呈現頁面後是靜態的,並且不使用客戶端編程就不能真正改變。由於表單動作決定了客戶端導航到的URL。 – fyrye

回答

0

你有幾個選擇這裏

1 - 將數據發送到服務器,任何URL diplayed,那麼服務器會返回一個乾淨的URL。

public function search(Request $request) 
{ 
    $tags = $request->tags; 
    return redirect()->to('search/' . $tags); //I assumed only one tag was passed 
} 

由此,您可以向用戶顯示乾淨的URL。當有多個標籤時,添加額外的logique。

2 - 使用JavaScript onclick上提交改寫

<input type="search" name="tags"> 
<input type="submit" onclick="window.location.href=this.form.action + this.form.q.value;" /> 
<!--/search/tags-->