jayan2358
V2EX  ›  PHP

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

  •  
  •   jayan2358 · Aug 12, 2018 · 4245 views
    This topic created in 3024 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
    unifier
    Aug 12, 2018
    1
    按钮的 onclick 事件里用 JS 跳转肯定是可以的
    不知道有没有其他暗黑科技可以简单实现
    rabbbit
    rabbbit
    Aug 12, 2018❤️1
    2
    <input id="a" value="1">
    <button onclick="window.location.pathname = '/task/' + a.value ">jump</button>
    wnh3yang
    wnh3yang
    Aug 12, 2018 via Android
    3
    这个表单直接 post 到服务器,然后 php 根据传来的数据 返回跳转响应
    DavidNineRoc
    DavidNineRoc
    Aug 12, 2018
    4
    这么明显的路由你自己偏要乱搞,本来 {thing} 就是要标记,
    jayan2358
    jayan2358
    OP
    Aug 12, 2018
    5
    @wnh3yang 我原先就是这么做的,可是这样太不美观了啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   847 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:17 · PVG 04:17 · LAX 12:17 · JFK 15:17
    ♥ Do have faith in what you're doing.