2012-11-02 54 views
0

我已經使用textbox多種數據類型創建了關鍵字的屬性類型。Umbraco XSLT使用所選關鍵字搜索複選框

然後將關鍵字分隔成由逗號分隔的單詞或短語列表。

我已將關鍵字封裝在A標記中,其中鏈接到我的搜索頁面的href包含關鍵字的值,以便所有具有相同關鍵字的節點都將顯示在我的搜索中。

我想添加一個選項,用戶可以使用關鍵字的值從複選框中進行選擇,然後提交搜索,以便所有檢查的關鍵字都包含在搜索中。

enter image description here

我需要搞清楚如何獲取關鍵字複選框列表的檢查值提交和顯示我的搜索頁面上的效果有所幫助。

這裏是我到目前爲止,不提交和我找不到在哪裏添加的複選框的值:

<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> 

任何援助將不勝感激。

乾杯,JV

我做了一些修改,現在有它半的工作。但是我的Umbraco模板有一個包裝我的內容的表單。我認爲這是造成一些問題的原因。

在我的測試中,我有一個包裝我的XSL代碼的表單。當我點擊「提交」按鈕時沒有任何反應,但如果我有相同的代碼副本,第二個複選框列表將能夠提交。此外,當我做出多項選擇時,搜索結果會嘗試查找不返回任何結果的「one,two」(/image-search.aspx?search=one & search = two)。它應該搜索「one 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> 

然後我嘗試下面的代碼,這並不需要來包裝形式的列表。同樣,多個選擇不起作用,而且返回的唯一結果是列表中的第一個輸入值(在本例中爲'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')" /> 

所以我需要哪個選項使用,以及如何將在搜索結果中選擇多個幫助。

+0

是否有一個原因,爲什麼你的''不有名字嗎?沒有名字的表單字段將不會被提交。另外,您在提交按鈕上添加了「onclick」事件處理程序的原因是什麼? – Tomalak

回答

1

的幾個注意事項

  • 你似乎是不知道的屬性值的模板。在大多數情況下,它們取代了對<xsl:attribute>的需求。使用大括號來評估屬性中的表達式。
  • 始終(!)將URL放入URL中的URL編碼值。下面比較tha <a href="...">
  • 當表單字段沒有名稱時,其值不會被瀏覽器提交。另一方面,ID不是必需的。
  • 使用<xsl:if test="string($anything) != ''>是沒有必要的。非空字符串是truthy,所以<xsl:if test="$anything">就足夠了。
  • 如果您希望傳輸表單,請勿在提交按鈕中使用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> 
+0

Thanks @Tomalek我在代碼的幫助下做了一些編輯 – JV10

+0

@ JV10在您更改的代碼中,您仍然在提交按鈕中使用onclick屬性。我曾兩次告訴你,這是無稽之談。你爲什麼繼續這樣做? – Tomalak

+0

@Tomalek我試圖找到通過多個複選框選項搜索關鍵字的最佳方法。隨着我的頁面內容已經包裝在一個表單中,會使用onclick屬性不起作用嗎?我應該在表格中填寫表格嗎?我怎麼讓搜索顯示多個選擇,從複選框列表。 – JV10