C0nw0nk
C0nw0nk

Reputation: 960

PHP Joomla appending to page title search input text

So I put together the following code

if ($this->state->get('filter.search')) {
$searchterm = $this->escape(JHtmlString::truncate($this->state->get('filter.search'), 160, true, false));

$this->document->setTitle("'" . $searchterm . "' Search | " . $title);
}

What will append/add what the user inputs in the search box to the page title.

Example :

Search box input :

"@~TEST"

What will create this HTML output :

<title>'&amp;quot;@~TEST&amp;quot;' Search | Devsite</title>

In my web browser it looks like this as the websites page title what does not look right and could use a filter of some kind.

'&quot;@~TEST&quot;' Search | Devsite

It seems to not display properly what have I done wrong or missing really it would be more friendly if it only outputs and displays friendly characters "A-Za-z0-9.-_"

Upvotes: 0

Views: 120

Answers (1)

C0nw0nk
C0nw0nk

Reputation: 960

The culprit is the following :

&amp;quot;

When it should be this :

&quot;

Solution is to stop double escaping if a value has already been escaped or gets escaped within another function it will cause this problem.

Removing this function since the text is getting escaped elsewhere already so lets not escape it again :

$this->escape() //remove this function from the string
$searchterm = $this->escape(JHtmlString::truncate($this->state->get('filter.search'), 160, true, false));

And making the output code this :

$searchterm = JHtmlString::truncate($this->state->get('filter.search'), 160, true, false);

Upvotes: 1

Related Questions