Hi, I’ve set up a job management system in PHP with MySQL db with some forms for adding / editing jobs and projects. However the client has now said that they want the ability to make formatting changes to the text that they type into a textarea field in the forms- for example, change color, make bold and so on. Then, after they save that record, when they view it later they want to be able to see the formatting changes, so they need to be saved into the MySQL db somehow.
I’ve had a look through text editors such as TinyMCE etc. but they all seem a bit of an overkill and not easy to add into a custom system like this which doesn’t have an inbuilt CMS. Is there any way I can add just a few buttons or functions to the textarea in the PHP form, so that the text can be made bold, have color changed or other basic changes? The formatting would need to be saved into the MySQL db record and would then be visible to the users when they open up the record again.
Textarea doesn’t support rich text. Those WYSIWYG editors you’re talking about use div with contenteditable="true" attribute set, instead of textarea:
<div contenteditable="true">This content will be editable</div>
And when you edit content in the div, editor puts its HTML code (as plain text with tags) into hidden textarea. You receive value of that hidden textarea when user submits form.
Google for “lightweight wysiwyg editor”. There are lots of them.
To integrate any of those editors (including monsters like TinyMCE) you usually have to just include its JS file to the page and run single line of JS code to replace your textarea with editor.
No, it’s quite easy. Here is how you add TinyMCE:
<textarea>This textarea will be replaced with TinyMCE</textarea>
<script src="//tinymce.cachefly.net/4.2/tinymce.min.js"></script>
<script>tinymce.init({selector:'textarea'});</script>