Capture "textarea" from the Responsive plugin WYSIWYG (text editor)

2

I have the following code:

<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>Untitled Document</title>

<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><scriptsrc="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

<link href="editor.css" type="text/css" rel="stylesheet"/>
<script src="editor.js"></script>

</head>

<body>

<div id="txtEditor"></div>

<script type="text/javascript">
$(document).ready( function() {
$("#txtEditor").Editor();                    
});
</script>

</body>
</html>

My question is how can I capture the information that is passed by the text editor in "DIV = txtEditor" to a textarea so that PHP can capture the data and send it by the post method to the database?

    
asked by anonymous 27.09.2014 / 05:17

3 answers

1

To get the value of the text, you use the following line, as in the following link: link

$('#txtEditor').Editor('getText');

I started last month using this text editor, and for me it was the best free WYSIWYG I found :)

    
10.02.2016 / 20:08
2

The TinyMCE site has this example; if you can change the DIV to a TextArea, you can do this:

<?php
 $allowedTags='<p><strong><em><u><h1><h2><h3><h4><h5><h6><img>';
 $allowedTags.='<li><ol><ul><span><div><br><ins><del>';  
// Should use some proper HTML filtering here.
  if($_POST['elm1']!='') {
    $sHeader = '<h1>Ah, content is king.</h1>';
    $sContent = strip_tags(stripslashes($_POST['elm1']),$allowedTags);
} else {
    $sHeader = '<h1>Nothing submitted yet</h1>';
    $sContent = '<p>Start typing...</p>';
    $sContent.= '<p><img width="107" height="108" border="0" src="/mediawiki/images/badge.png"';
    $sContent.= 'alt="TinyMCE button"/>This rover has crossed over</p>';
  }
?>
<html>
<head>
<title>My test editor - with tinyMCE and PHP</title>
<script language="javascript" type="text/javascript" src="/js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
  tinyMCE.init({
    theme : "advanced",
    mode: "exact",
    elements : "elm1",
    theme_advanced_toolbar_location : "top",
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,"
    + "justifyleft,justifycenter,justifyright,justifyfull,formatselect,"
    + "bullist,numlist,outdent,indent",
    theme_advanced_buttons2 : "link,unlink,anchor,image,separator,"
    +"undo,redo,cleanup,code,separator,sub,sup,charmap",
    theme_advanced_buttons3 : "",
    height:"350px",
    width:"600px"
});

</script>
</head>
<body>
 <?php echo $sHeader;?>
 <h2>Sample using TinyMCE and PHP</h2>
 <form method="post" action="<?=$_SERVER['REQUEST_URI']?>">
  <textarea id="elm1" name="elm1" rows="15" cols="80"><?php echo $sContent;?></textarea>
<br />
<input type="submit" name="save" value="Submit" />
<input type="reset" name="reset" value="Reset" />
</form>
</body>
</html>

Source: link

    
27.09.2014 / 14:13
0

You can capture content that is in the "texteditor" ID with jQuery as long as it has content in it ... example:

//Verifica se há conteúdo!
if($('#texteditor').html() != ""){

  //Cria uma variavel para pegar o conteúdo!
  var content = $('#texteditor').html();

    //Inicia o envio!
    $.ajax({
        url: 'sua_pagina.php',
        type: 'POST',
        data: {
        content: content
        },
        success: function(data){
            if(data){

                //Em caso de sucesso, faça alguma coisa aqui!

            }else{

                //Em caso de erro, faça algo aqui!
            }
        }
    });

}else{//Caso a tentativa de envio esteja sem conteúdo!

     //Adicione alguma ação aqui!

}

Now for a PHP page I leave only one idea, you work it as well to find better .. remembering that return will be true or false represented by 0 or 1 !!!

<?php

$content = $_POST['content']; //peda os dados do POST
$content = mysql_real_escape_string($content);  //escapa a string

$sql = true; // aqui você pode colocar sua SQL para salvar no banco

if ($sql)
{
    echo 1;
}else{
    echo 0;
}
    
27.09.2014 / 14:38