How to save the generated HTML from wysihtml5 or pass it to PHP page

10,491

EDIT: You need to add a name attribute to your textarea for it to be posted to your PHP. I completely forgot this. So forget every other modifications I did, just do this to your textarea in your original code :

<textarea class="textarea" id="content" name="content" placeholder="Enter text ..."></textarea>

You should also send the values through a POST request because sending the html in the URL arguments is not a good idea.

Old Answer:

You need to also post the html when submitting the form. There are multiple ways to do this but as an example you can add an hidden input field in which you will store the html before sending it to php.

First I changed a bit your html, the form is now sent through a POST request which is better than through the URL arguments if you want to send HTML:

<form id="myform" action="save.php" method="POST">
   <textarea class="textarea" id="content" placeholder="Enter text ..."></textarea>
   <input type="submit" class="btn btn-primary" />
   <input type="hidden" id="html" />
</form>

Add the javascript event to change the hidden field value before submitting the value:

$("#myform").submit(function() {
   // Retrieve the HTML from the plugin
   var html = $('#content').val();
   // Put this in the hidden field
   $("#html").val(html);
});
Share:
10,491
Alok Kumar
Author by

Alok Kumar

Updated on September 04, 2022

Comments

  • Alok Kumar
    Alok Kumar over 1 year

    I am using bootstrap-wysihtml5 to implement WYSIHTML Editor in my bootstrap site. But I dont get hoow can I pass the HTML content to a php page in order to save the content in database. Though I have used ID(content) for the textarea but the php page is not getting data. The URL by "Get" shows "?_wysihtml5_mode=1" at the end instead of something like "?content=..."

    <form action="save.php" method="get">
       <textarea class="textarea" id="content" placeholder="Enter text ..."></textarea>
       <input type="submit" class="btn btn-primary" />
    </form> 
    
    <script>$('#content').wysihtml5(); </script>