How to save generated HTML from wysihtml5 or transfer it to a PHP page

I use bootstrap-wysihtml5 to implement the WYSIHTML editor on my boot site. But I don't get hoow, can I pass the HTML content to the php page to save the content in the database. Although I used ID (content) for the text field, but the php page does not receive data. The get URL shows "? _Wysihtml5_mode = 1" at the end, and not 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> 
+4
source share
2 answers

EDIT . You need to add the name attribute to the text box so that it is published in your PHP. It slipped from my mind. So forget all the other changes I made, just do this in your text box in your source code:

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

You should also send values ​​through a POST request, because sending html to the url arguments is not a good idea.

Old answer:

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

At first I changed your html a bit, the form is now submitted via a POST request, which is better than using 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 a javascript event to change the value of the hidden field before sending the value:

 $("#myform").submit(function() { // Retrieve the HTML from the plugin var html = $('#content').val(); // Put this in the hidden field $("#html").val(html); }); 
+3
source
 <script> $('#content').wysihtml5(); $(document).ready(function() { $('.btn btn-primary').click(function() { var content = $('#content').html(); $.ajax({ url: 'update.php', type: 'POST', data: { content: content } }); }); }); </script> <form> <textarea class="textarea" id="content" placeholder="Enter text ..."></textarea> <input type="submit" class="btn btn-primary" /> </form> 

update.php

 <?php DATABASE_CONNECTION $GET_THE_CONTENT_HERE = $_POST[content]; INSERT TO DATABASE ?> 
0
source

All Articles