< 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.

< char hides data in list or view page

Postby braven » Sat Jan 06, 2018 12:25 am

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?
braven
 
Posts: 3
Joined: Wed Dec 27, 2017 9:30 pm

Re: < char hides data in list or view page

Postby sangnandar » Sat Jan 06, 2018 8:55 am

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 "&lt;" and/or "&gt;"
For example:
if (substr($this->FieldName->ViewValue,0,1) == "<")
$this->FieldName->ViewValue = "&lt;".substr($this->FieldName->ViewValue,1);

Or you can add space in between those characters so browsers don't see it as tags.
sangnandar
 
Posts: 293
Joined: Mon Sep 19, 2016 2:04 am

Re: < char hides data in list or view page

Postby arbei » Sat Jan 06, 2018 11:21 am

You can set up the [View Tag] -> [Format] as "String" and use the function "htmlspecialchars" to display them.
arbei
 
Posts: 1499
Joined: Wed Sep 09, 2015 10:13 am

Re: < char hides data in list or view page

Postby braven » Sat Jan 06, 2018 6:35 pm

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
 
Posts: 3
Joined: Wed Dec 27, 2017 9:30 pm

Re: < char hides data in list or view page

Postby braven » Tue Jan 09, 2018 9:07 pm

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
braven
 
Posts: 3
Joined: Wed Dec 27, 2017 9:30 pm


Return to General Discussion (PHPMaker)