Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving changes made when editing with /wysihtml5

Tags:

html

save

editing

I am looking for some guidance on how to save editing done using /wysihtml5.

I have googled using several different combinations of search terms but virtually all the hits I get are github. I have looked through the examples on that site but I can't find anything that explains how the changes can be saved once a user edits a page.

I do have some php and sql knowledge but would like some pointers to exactly what I need to do to get changes made using /wysihtml5 saved. The other instructions appear very comprehensive so I wonder why this aspect seems to be missing.

Can anyone help please?

Many thanks

Brenda

like image 773
user1644918 Avatar asked Sep 15 '26 12:09

user1644918


1 Answers

According to the editor's Getting Started page, it works by replacing a regular <textarea> with the rich editor:

wysihtml5 takes a textarea and transforms it into a rich text editor. The textarea acts as a fallback for unsupported browsers (eg. IE < 8). Make sure the textarea element has an id, so we can later access it easily from javascript. The resulting rich text editor will much behave and look like the textarea since behavior (placeholder, autofocus, …) and css styles will be copied over.

Please note: The textarea will always hold the editor’s generated markup. Therefore wysihtml5 integrates smoothly with forms.

So, the editor's content will always be available as the value of the textarea, and you can use it as you would with a regular form element (submit the form, or get the contents with JavaScript and send it to PHP using Ajax).

For example, consider you apply the editor to the following:

<form action="somescript.php" method="POST">
    <textarea id="wysihtml5-textarea" name="wysihtml5-textarea"></textarea>
    <input type="submit" value="Submit form">
</form>

If you submit the form by clicking the button, your php script will receive the contents on $_POST["wysihtml5-textarea"] (change the name of the textarea to set the desired key on $_POST).

If you want to get the value using JavaScript, select the <textarea> by ID, then access the element's value:

var textarea = document.getElementById("wysihtml5-textarea");
alert(textarea.value);

Then you can pass that value to PHP using Ajax if you want. The PHP/SQL implementation for actually saving the data is up to you, the editor's code just takes care of providing a rich text editor, and formatting features.

Note: I never used that editor, so my answer might be not be 100% accurate.

like image 113
bfavaretto Avatar answered Sep 17 '26 04:09

bfavaretto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!