- I am using HTML textarea for user to input some data and save that to App Engine's model
- The problem is that when I retrieve the content it is just text and all formatting is gone
- The reason is because in textarea there is no formatting that we can make
Question:
- is there any way to retain the format that user provides?
- is there any other element(other than textarea), that i'll have to use?(which one?)
P.S I am very new to area of web development and working on my first project
Thank you
What you want is a Rich Text Editor. The standard HTML
<textarea>
tag only accepts plain text (even if the text is or includes HTML markup). There are a lot of example out there (including some listed on the page linked) but I would highly recommend using a prepackaged one for this. Coding your own is fairly complicated for people who are new, and even for a lot who have some experience. Both TinyMCE and CKEditor are very common ones, but there are many others as well.This won't solve the case when you want somebody to be able to format their text (e.g. with WYSIWYG bold buttons etc.), but if you want to be able to accept pre-formatted HTML (e.g. copy and paste from other HTML source such as a webpage), then you can do this:
This uses a
contenteditable
div
element which you can format to look like an input box and will accept pasted HTML, and a hiddentextarea#foo
which will be populated with the pasted HTML just before the form is submitted.Note that this is not an accessible solution as it stands.
A text box is like wordpad, you cant format it, if you paste in from word or any other formatted text it will wipe all the formatting and you will be left with just the text.
You need add an editor to the text areas, I use TinyMCE, but there are many other out there too.
To implement you need to have all the source (which you can get from TinyMCE) in your web directory.
Here's an example which you can try:
Add this the the head section of your page:
Then to call the textarea:
NB: You need to download and have in your directory the js files for
<script language="javascript" type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
Hope this helps!