Question

I have made one form in which there is rich text editor. and i m trying to store the data to database.
now i have mainly two problem..

1) As soon as the string which contents "#"(basically when i try to change the color of the font)     character, then it does not store characters after "#". and it also not store "#" character also.

2) although i had tried....in javascript

html.replace("\"","'");

but it does not replace the double quotes to single quotes.

Was it helpful?

Solution

We'll need to see some code. My feeling is you're missing some essential escaping step somewhere. In particular:

As soon as the string which contents "#"(basically when i try to change the color of the font) character

Implies to me that you might be sticking strings together into a URL like this:

var url= '/something.php?content='+html;

Naturally if the html contains a # symbol, you've got problems, because in:

http://www.example.com/something.php?content=<div style="color:#123456">

the # begins a fragment identifier called #123456">, like when you put #section on the end of a URL to go to the anchor called section in the HTML file. Fragment identifiers are purely client-side and are not sent to the server, which would see:

http://www.example.com/something.php?content=<div style="color:

However this is far from the only problem with the above. Space, < and = are simly invalid in URLs, and other characters like & will also mess up parameter parsing. To encode an arbitrary string into a query parameter you must use encodeURIComponent:

var url= '/something.php?content='+encodeURIComponent(html);

which will replace # with %35 and similarly for the other out-of-band characters.

However if this is indeed what you're doing, you should in any case you should not be storing anything to the database in response to a GET request, nor relying on a GET to pass potentially-large content. Use a POST request instead.

OTHER TIPS

It seems that you are doing something very strange with your database code. Can you show the actual code you use for storing the string to database?

# - character is a common way to create a comment. That is everything starting from # to end of line is discarded. However if your code to store to database is correct, that should not matter.

Javascript is not the correct place to handle quote character conversions. The right place for that is on server side.

As you have requested....
I try to replay you... I try to mention exact what I had done...

1) on the client side on the html form page I had written like this..

html = html.trim();    // in html, the data of the rich text editor will come.
document.RTEDemo.action = "submit.php?method='"+ html.replace("\"","'") + "'"; 
\\ i had done replace bcz i think that was some problem with double quotes.

now on submit.php , my browser url is like this...

http://localhost/nc/submit.php?method='This is very simple recipe.<br><strong style='background-color: #111111; color: #80ff00; font-size: 20px;">To make Bread Buttor you will need</strong><br><br><blockquote><ol><li>bread</li><li>buttor</li></ol></li></blockquote><span style="background-color: #00ff80;">GOOD.</span><br><br><br><blockquote><br></blockquote><br>'


2) on submit.php ........I just write simply this

echo "METHOD : ".$_GET['method'] . "<br><br>";
$method = $_GET['method'];

now my answer of upper part is like this...

METHOD : 'This is very simple recipe.

now i want to store the full detail of URL....but its only storing...

This is very simple recipe.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top