0

我使用文本框多数据类型创建了关键字的属性类型。

然后将关键字分隔成以逗号分隔的单词或短语列表。

我已将关键字包装在 A 标记中,带有链接到我的搜索页面的 href,并包含关键字的值,以便具有相同关键字的所有节点都将显示在我的搜索中。

我想添加一个选项,用户可以从带有关键字值的复选框中进行选择,然后提交搜索,以便所有选中的关键字都包含在搜索中。

在此处输入图像描述

我需要帮助弄清楚如何获取关键字复选框列表的选中值以提交并在我的搜索页面上显示结果。

这是我到目前为止所拥有的,它没有提交,我找不到在哪里添加复选框的值:

<xsl:if test="string($currentPage/keywords) != ''">

<!-- get the contents of the textbox multiple, with commas -->
<xsl:variable name="textWithBrs" select="umbraco.library:ReplaceLineBreaks($currentPage/keywords)"/>

<!-- replace commas with pipes so you can use Split -->
<xsl:variable name="textWithPipes" select='umbraco.library:Replace($textWithBrs, ", ", "|")'/>

<!-- split into an array of items and output as unordered list -->
<xsl:variable name="items" select="umbraco.library:Split($textWithPipes, '|')"/>
<ul>
  <xsl:for-each select="$items/value">
    <li>
      <input type="checkbox" value="true" keyword="{.}" id="{.}" name=""/>
      <a>
      <xsl:attribute name="href"> <xsl:text disable-output-escaping="yes">/imagery/image-search.aspx
      <![CDATA[?]]>
      search=</xsl:text> <xsl:value-of select="." /> </xsl:attribute>
      <xsl:attribute name="title"> <xsl:value-of select="."/> </xsl:attribute>
      <xsl:value-of select="."/> </a> </li>
  </xsl:for-each>
</ul>
<input type="submit" value="Search" id="btnSearchBottom" name="" onclick="location.href='/imagery/image-search.aspx?search=otbra'" />
</xsl:if>

任何帮助将不胜感激。

干杯,合资企业

我已经进行了一些编辑,现在让它半工作。但是,我的 Umbraco 模板有一个包含我的内容的表单。我认为这是导致一些问题的原因。

在我的测试中,我有一个包装我的 XSL 代码的表单。当我单击“提交”按钮时,没有任何反应,但如果我有相同代码的副本,则第二个复选框列表将能够提交。此外,当我进行多项选择时,搜索结果会尝试查找不返回任何结果的“一,二”(/image-search.aspx?search=one&search=two)。它应该搜索“一二”(/image-search.aspx?search=one%20two)。

我的重复形式的代码:

<div style="display:none;">
  <form name="input" action="/imagery/image-search.aspx" method="get">
    <ul>
      <xsl:for-each select="$items/value">
        <li>
          <input type="checkbox" name="search" value="{.}"/>
          &nbsp; <a href="/imagery/image-search.aspx?search={umbraco.library:UrlEncode(.)}" title="{.}"> <xsl:value-of select="."/> </a> </li>
      </xsl:for-each>
    </ul>
    <input type="submit" value="Submit"/>
  </form>
</div>
<div>
  <form name="input" action="/imagery/image-search.aspx" method="get">
    <ul>
      <xsl:for-each select="$items/value">
        <li>
          <input type="checkbox" name="search" value="{.}"/>
          &nbsp; <a href="/imagery/image-search.aspx?search={umbraco.library:UrlEncode(.)}" title="{.}"> <xsl:value-of select="."/> </a> </li>
      </xsl:for-each>
    </ul>
    <input type="submit" value="Submit"/>
  </form>
</div>

Then I tried the following code, which didn't require to wrap the list in a form. Again multiple selections don't work, but also the only result returned is the first input value in the list (in this case 'one').

<ul id="checkboxes">
  <xsl:for-each select="$items/value">
    <li>
      <input id="{.}" type="checkbox" name="search" value="{.}"/>
      &nbsp; <a href="/imagery/image-search.aspx?search={umbraco.library:UrlEncode(.)}" title="{.}"> <xsl:value-of select="."/> </a> </li>
  </xsl:for-each>
</ul>
<input name="searchbutton" class="button" value="Search" type="reset" onClick="location.href='/imagery/image-search.aspx?search=' + $('#checkboxes input').attr('value')" />

So I need help with which option to use, and how to include multiple selections in the search result.

4

1 回答 1

1

A few notes

  • You seem to be unaware of attribute-value-templates. They replace the need for <xsl:attribute> in most cases. Use curly braces to evaluate expressions in attributes.
  • Always (!) URL-encode values that you put into an URL. Compare tha <a href="..."> below.
  • When a form field does not have a name, its value will not be submitted by the browser. An ID on the other hand is not necessary.
  • Using <xsl:if test="string($anything) != ''> is not necessary. A non-empty string is truthy, so <xsl:if test="$anything"> is sufficient.
  • onclick如果您希望表单传输,请勿在提交按钮中使用。使用该<form action="...">参数来确定应将表单值传输到何处。或者使用 JavaScript,但完全避免使用内联脚本处理程序,例如"onclick". 您的标记中根本不应该有 JS。

XSL 代码

<xsl:if test="$currentPage/keywords">
  <xsl:variable name="textWithBrs" select="
    umbraco.library:ReplaceLineBreaks($currentPage/keywords)
  "/>
  <xsl:variable name="textWithPipes" select="
    umbraco.library:Replace($textWithBrs, ', ', '|')
  "/>
  <xsl:variable name="items" select="
    umbraco.library:Split($textWithPipes, '|')
  "/>
  <ul>
    <xsl:for-each select="$items/value">
      <li>
        <input type="checkbox" value="true" keyword="{.}" name="keywords"/>
        <a href="/imagery/image-search.aspx?search={umbraco.library:UrlEncode(.)}" title="{.}">
          <xsl:value-of select="."/>
        </a>
      </li>
    </xsl:for-each>
  </ul>
  <input type="submit" value="Search" id="btnSearchBottom" />
</xsl:if>
于 2012-11-02T08:04:34.330 回答