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