Page 1 of 1

< char hides data in list or view page

Posted: Sat Jan 06, 2018 12:25 am
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?


Re: < char hides data in list or view page

Posted: Sat Jan 06, 2018 8:55 am
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.


Re: < char hides data in list or view page

Posted: Sat Jan 06, 2018 11:21 am
by arbei

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


Re: < char hides data in list or view page

Posted: Sat Jan 06, 2018 6:35 pm
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).


Re: < char hides data in list or view page

Posted: Tue Jan 09, 2018 9:07 pm
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