How to deal with html entities in grid and database

I have an app that allows me to submit text to a grid via a addrow() routine… and pushes the data out via a defined dataProcessor. Since the user can input text with less than, greater than, ticks, slashes etc… I have to replace them before attempting to store in a database. Its maddening…

I am having to do things like this -
additem=additem.replace(/,/g, “,”);
additem=additem.replace(/’/g, ‘'’);
additem=additem.replace(/</g, ‘&lt;’); // less than sign
additem=additem.replace(/>/g, ‘&#62;’); //gt sign

//couldnt get these replacements to work… moved replacing these to the dbupdateall script
//additem=additem.replace(///g, ‘&#47;’); //backslash
//additem=additem.replace(/\/g, ‘&#92;’);

It also creates an issue that if text is added to the grid, and manipulated inline, the behavior is a little different. If I substitute the data like above… it will initially display nicely to the user, but if they edit the txt field, the editable text is translated with the html entities.

I have been trying to figure out how to deal with it. Scouring the documentation etc. I looked into CDATA blocks… but cant get anything to work for all elements. and I always end up with presenting the replacement characters to the user instead of the readable data.

My goal is to allow the user to input data in any form, and have any needed translations needed done under the hood and invisible to the user.

Has anyone else dealt with this kind of thing? Would changing to JSON help with any of this?

Any help would be greatly appreciated.

For displaying the data in the grid as a text please, try to use the edtxt/rotxt/txttxt excell types instead of ed/ro/txt.