将表单输入值传递给URL

mob*_*ile 2 php forms hyperlink

这里总有新人到HTML.

我想创建一个搜索框,将输入的搜索词传递到URL字段.

这是我的输入表格:

<form name="search" action="/search/" method="post">
    <input type="text" name="topic" value="">
</form>
Run Code Online (Sandbox Code Playgroud)

我想将搜索字词/search/放在网址中.如何才能做到这一点?

谢谢.

G-N*_*get 5

使用GET表单方法:

<form name="search" action="/search/" method="GET">
    <input type="text" name="topic" value="" />
</form>
Run Code Online (Sandbox Code Playgroud)

编辑:

要获取表单将用户发送到/ search //这样的网址,您可以使用如下的javascript函数:

function submitForm(){
    var url = '/search/';
    url += document.search.topic.value + '/';
    // repeat the above line for any other fields you may want to add
    window.location.href = url;
}
Run Code Online (Sandbox Code Playgroud)

然后,您可以将此函数用作onClick提交按钮或表单上的处理程序onSubmit.