dopod0901 2012-06-01 10:07
浏览 20
已采纳

如何将简单的搜索查询传递到URL?

I have a search form on my site, and I want to pass the text in the form to the URL, like: mysite.com/search.php?q=apples (if search word was apples).
I figure that way people can bookmark their searches.

One solution I thought would be to catch the searchword in search.php and then reload into a new made URL. But it's not very elegant to reload like that. So how can I do it - I mean, how is it normally done? Do I need to use jQuery?

Clarification: I know how to get the vars from the URL in php. What I need is to control the URL that will be opened when the user presses SUBMIT, and the URL needs to contain the user's search word! Just like Google or DuckDuckGo, I put "apples" and the URL becomes ...?q=apples. But - how?! (Then I'll pick that up in the search.php, of course, but I know how to do that.) This is what I have now:

<div id="topnav">
<form action="search.php" method="post">
<input name="searchword" type="text">
<input type="submit">
</form>

Thank you so much.

  • 写回答

5条回答 默认 最新

  • dongtu0363 2012-06-01 10:13
    关注

    Upon reading the clarification. What you need is a search form that submits to your search.php for example:

    <form action="search.php" method="get">
    <input type="text" value="search word" name="q" />
    <input type="submit" value="submit" />
    </form>
    

    This will pass whatever value entered in the input named q to the search.php script.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊