As far as I'm aware, there isn't a way using the umbraco.library XSLT extensions to do this. You'd need to know the name of the item.
If you are able to write a custom XSLT extension, here's a bit of code that you might find useful?
public static XPathNodeIterator GetRequestForm()
{
XmlDocument xd = new XmlDocument();
xd.LoadXml(String.Concat("<Request.Form />"));
NameValueCollection nvc = HttpContext.Current.Request.Form;
if (nvc != null)
{
try
{
for (int i = 0; i < nvc.Count; i++)
{
XmlNode node = xmlHelper.addCDataNode(xd, nvc.GetKey(i), nvc.Get(i));
xd.DocumentElement.AppendChild(node);
}
}
catch (Exception ex)
{
xd.DocumentElement.AppendChild(xmlHelper.addTextNode(xd, "error", ex.Message));
}
}
else
{
xd.DocumentElement.AppendChild(xmlHelper.addTextNode(xd, "error", String.Concat("The Request.Form object is empty.")));
}
return xd.CreateNavigator().Select("/");
}
This will return an XML node-set that you can loop through in your XSLT. From there you can check if the checkbox value is "on".
You can customise the above code snippet to use any of the Request objects that inherit from a NameValueCollection - like Request.QueryString or Request.ServerVariables, (unfortunately Request.Cookies inherits from HttpCookieCollection, so can't be used here).
Looping through form and checkboxes?
Hi,
Is there a way in XSLT to loop through a bunch of checkboxes and return just the checked ones using umbraco.library:Request?
The checkboxes are dynamically generated so I do not know their names.
Many Thanks,
Rich
Hi Rich,
As far as I'm aware, there isn't a way using the umbraco.library XSLT extensions to do this. You'd need to know the name of the item.
If you are able to write a custom XSLT extension, here's a bit of code that you might find useful?
This will return an XML node-set that you can loop through in your XSLT. From there you can check if the checkbox value is "on".
You can customise the above code snippet to use any of the Request objects that inherit from a NameValueCollection - like Request.QueryString or Request.ServerVariables, (unfortunately Request.Cookies inherits from HttpCookieCollection, so can't be used here).
Good luck, Lee.
Hey Lee,
Thanks so much for your reply, looks like what I need!
Will let you know how I get on when I try to implement it.
Cheers
Rich
is working on a reply...