< char hides data in list or view page

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
braven
User
Posts: 39

< char hides data in list or view page

Post by braven »

I have an existing database containing some columns with data containing characters like <, >, *, & etc. This works fine in an Edit page. In a List or View page the data becomes invisible when the first character is <.

I have set character set to utf-8.

Somebody knows an easy way to fix this?


sangnandar
User
Posts: 980

Post by sangnandar »

I can confirm it happens on my side too. Although the problem is only with <Text character without space in between.
<Text ; //this is problem
< Text ; // with space in between, not a problem.
Character * and > works fine.

For example:
My <b> Text ; // will output as My Text with bold "Text", as browser automatically supplied the closing </b> tag (tested on Chrome and FF).
<Text ; // browser will see it as an opening tag and supplied the closing </Text>.
Check your HTML to see how it goes.

To get rid of this problem, you need to replace html tags < and/or > in your strings with "<" and/or ">"
For example:
if (substr($this->FieldName->ViewValue,0,1) == "<")
$this->FieldName->ViewValue = "<".substr($this->FieldName->ViewValue,1);

Or you can add space in between those characters so browsers don't see it as tags.


arbei
User
Posts: 9286

Post by arbei »

You can set up the [View Tag] -> [Format] as "String" and use the function "htmlspecialchars" to display them.


braven
User
Posts: 39

Post by braven »

Hmm, I guess I can encode the html characters in code, but I would have to do that with several different table columns. I would expect PHPMaker to make the fields html safe by default and not to handle that different for different page types (it is handled OK for Edit pages).


braven
User
Posts: 39

Post by braven »

Ok, did some testing and ran into an additional issue on Master-detail pages with using the Currentpage() function initially. Have the workaround working now. I used a Custom View Tag with just one line of code:

<?php echo htmlspecialchars(Page("MyTableName")->MyFieldName->CurrentValue);?>

This seems to work now for all page types including Master-detail.

Cheers


Post Reply