How show HTML as text string in phpgrid column?

QuestionsHow show HTML as text string in phpgrid column?
Nikul Panchal asked 5 years ago

i have created phpgrid, just getting 1 issue, when i load grid, it loads as HTML, I want to convert it as HTML text string, i am using below function which converts HTML as HTML text string, but when i try to edit string, it removes HTML tags, i am using below function

$col[“formatter”] = “function(cellval,options,rowdata){ return jQuery.jgrid.htmlDecode(cellval); }”;
$col[“unformat”] = “function(cellval,options,rowdata){ return jQuery.jgrid.htmlEncode(cellval); }”;

And when i use this code $col[“formatter”] = true; It saves HTML tags in database, but it doesn’t load HTML text string in phpgrid column, can anyone please help to resolve this issue ?
I need both need to load HTML text string in PHPGrid column and also need to store data  as HTML tags, any help will be really appreciated.

5 Answers
Abu Ghufran Staff answered 5 years ago

You need to encode content as html entities in formatter (while displaying)
and on edit decode it again to make html tags.

With that column, set:

$col[“formatter”] = “function(cellval,options,rowdata){ return jQuery.jgrid.htmlEncode(cellval); }”;
$col[“unformat”] = “function(cellval,options,rowdata){ return jQuery.jgrid.htmlDecode(cellval); }”;

Code: https://gist.github.com/gridphp/1a445547447935288c6514f7d7b3a3ef#file-html-editor-raw-php-L97

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
James Davis answered 2 years ago

I’m trying this and it is not working right. It is stripping out some of my HTML tags in my string saved in Database. Basically when the PHPGrid loads the String from database which has HTML tags it is removing some of them but not all. Weird and I cannot figure this out as I have the exact same use-case.

James answered 2 years ago

So I’m using this code:

$col[“edittype”] = “textarea”; // render as textarea on edit

$col[“formatter”] = “function(cellval,options,rowdata){ return jQuery.jgrid.htmlEncode(cellval); }”;

$col[“unformat”] = “function(cellval,options,cell){ return jQuery.jgrid.htmlDecode(cellval); }”; $cols[] = $col;

the part of my HTML String getting cut out on save of the edit is here:

<!DOCTYPE html>

<html lang=”en” xmlns:o=”urn:schemas-microsoft-com:office:office” xmlns:v=”urn:schemas-microsoft-com:vml”>
<head>
<title>

All META tags are also getting removed on Edit save.

Any idea why I’ve been debugging this for a long time. PostgreSQL is the database.

Abu Ghufran Staff answered 2 years ago

There is no such limitation of length. Please make sure you database field size is enough to store. Grid also sanitizes the posted input and removes scripts and possibly harmful xss tags.

You can disable it by setting:

$col["sanitize"] = false;
_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
James Davis answered 2 years ago

That fixed it, thank you so much for this great product and support!

Your Answer

11 + 17 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?