jayan2358
V2EX  ›  PHP

如何实现点击表单提交按钮,网页跳转至一个由表单内容拼接而成的 URL?

  •  
  •   jayan2358 · Aug 12, 2018 · 3895 views
    This topic created in 2856 days ago, the information mentioned may be changed or developed.
    路由

    Route::get('/task/{thing}', 'TaskController@show');
    视图

    <form action="/task" method="get">
    <input type="text" name="thing" />
    <input type="submit" />
    </form>
    如果这样写跳转链接将会是 /task?thing=dsadsa 形式,如何优雅的跳转到 /task/dsadsa 这种形式的 URL
    5 replies    2018-08-12 22:03:06 +08:00
    unifier
        1
    unifier  
       Aug 12, 2018
    按钮的 onclick 事件里用 JS 跳转肯定是可以的
    不知道有没有其他暗黑科技可以简单实现
    rabbbit
        2
    rabbbit  
       Aug 12, 2018   ❤️ 1
    <input id="a" value="1">
    <button onclick="window.location.pathname = '/task/' + a.value ">jump</button>
    wnh3yang
        3
    wnh3yang  
       Aug 12, 2018 via Android
    这个表单直接 post 到服务器,然后 php 根据传来的数据 返回跳转响应
    DavidNineRoc
        4
    DavidNineRoc  
       Aug 12, 2018
    这么明显的路由你自己偏要乱搞,本来 {thing} 就是要标记,
    jayan2358
        5
    jayan2358  
    OP
       Aug 12, 2018
    @wnh3yang 我原先就是这么做的,可是这样太不美观了啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   859 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 20:38 · PVG 04:38 · LAX 13:38 · JFK 16:38
    ♥ Do have faith in what you're doing.