我已經使用textbox多種數據類型創建了關鍵字的屬性類型。Umbraco XSLT使用所選關鍵字搜索複選框
然後將關鍵字分隔成由逗號分隔的單詞或短語列表。
我已將關鍵字封裝在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>
任何援助將不勝感激。
乾杯,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="{.}"/>
<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="{.}"/>
<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="{.}"/>
<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')" />
所以我需要哪個選項使用,以及如何將在搜索結果中選擇多個幫助。
是否有一個原因,爲什麼你的''不有名字嗎?沒有名字的表單字段將不會被提交。另外,您在提交按鈕上添加了「onclick」事件處理程序的原因是什麼? – Tomalak