【问题标题】:Include form data in the middle of "action" attribute在“action”属性中间包含表单数据
【发布时间】:2012-03-21 17:07:19
【问题描述】:

我正在努力在 Wordpress 中为基于 ContentDM (http://www.oclc.org/support/questions/contentdm/default.htm) 的内容库构建一个更加用户友好的前端访问页面。作为网站的一部分,请求的其中一项内容是一个搜索表单,该表单不是搜索 Wordpress,而是转到 ContentDM 库并在那里搜索。

看来 ContentDM 的搜索语法如下:

http://libraryID.contentdm.oclc.org/cdm/search/searchterm/INPUT_TERM/order/nosort

“INPUT_TERM”是用户搜索的任何内容。

换句话说,为了创建一个直接进入那里的搜索表单,我必须将输入元素的内容动态插入到表单的“action”属性的中间。

我猜我最好的选择是将其发送到一个 PHP 页面,该页面将 $_POST['whatever'] 粘贴到 URL 中并进行重定向。但实际上有没有一种方法可以从表单中动态完成(最好没有 Javascript)并保存一个步骤?

谢谢!

【问题讨论】:

  • 如果你真的想要...在字段更改时使用 javascript 更改操作。

标签: php html forms search input


【解决方案1】:

我想这样的事情可能会奏效:

<form action="" method="get"
    onSubmit="location.href='http://libraryID........./'+this.children[0].value+'/order/nosort; return false;">
    Search: <input type="search" />
    <input type="submit" value="Go" />
</form>

这会将浏览器重定向到搜索框中给出的搜索页面,但它并不是非常可靠。

您可能想查看是否有 URL 的查询字符串“版本” - 也许该搜索 URL 受 mod_rewrite 影响以“看起来很漂亮”,并且您可能可以将 http://libraryID.contentdm.oclc.org/cdm/search 作为操作,并拥有名为searchterm的输入字段:

<form action="http://libraryID.contentdm.oclc.org/cdm/search" method="get">
    Search: <input type="search" name="searchterm" />
    <input type="submit" value="Go" />
</form>

【讨论】:

  • 谢谢!是的,我想我会查找搜索字符串的其他版本。他们的文档不是最容易使用的。 >.
猜你喜欢
  • 1970-01-01
  • 2023-01-21
  • 2022-01-25
  • 2023-04-01
  • 2023-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多