Page 1 of 1

PART SOLVED - Valid xhtml - encoding ampersand

Posted: Fri Feb 06, 2009 5:39 pm
by lainyrache
Hi all

My website is failing xhtml validation because of a few un-encoded ampersands.
I am hoping there is a tag, or some code I can use to convert the '&' to a '&', as it works in menus and the breadcrumb trail.

It happens in 2 places:

1. in the {menutext} udt, here's the  code:

Code: Select all

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'root_page_menutext';
if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
    $currentContent =& $currentNode->getContent();
    $result = $currentContent->menutext();
    $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);
2. and in the form action on the search results page. eg:

Code: Select all

<form id="cntnt01moduleform_1" method="get" action="http://www.lalala.org.uk/cms1/cms2/?mact=Search%2Ccntnt01%2Cdosearch%2C0&cntnt01returnid=109&cntnt01searchinput=lorem&submit=Go&cntnt01origreturnid=15">
I'm sure I've seen the answer to this somewhere on the forum, but of course now I need it I can't find it anywhere.
Has anyone done this before?
Thanks for any help
Rachael

Re: PART SOLVED - Valid xhtml - encoding ampersand

Posted: Thu Feb 12, 2009 11:34 am
by lainyrache
Just in case anybody else is looking for this fix - I have managed to encode the ampersand in the {menutext} tag, by using cms_htmlentities

So the code for my menutext udt is now:

Code: Select all

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$var = 'root_page_menutext';
if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
    $currentContent =& $currentNode->getContent();
    $result = cms_htmlentities($currentContent->menutext());
    $currentNode =& $currentNode->getParentNode();
}
$smarty->assign($var,$result);
Still struggling with the ampersands in the search action!