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

Asked

Viewed 2,217 times

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>
<script src="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 on "DIV = txtEditor" to a textarea so that PHP can capture the data and send by post method to the database?

  • I am currently using the editor Tinymce. It is used by large companies and fully configurable, not to mention easy to implement, just create a <textarea> performing the bind with your template and initialize the plugin <script>tinymce.init({selector:'textarea'});</script>

  • João. How exactly this bind works, with this plugin Responsive WYSIWYG (text editor)r?

  • Well, I’m a Java developer, but the principle is the same. you have the name attribute in which you link to popular or save the information

3 answers

2

On the site Tinymce has this example; if you can change the DIV to a Textarea, you can do so:

<?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: http://www.tinymce.com/wiki.php/TinyMCE3x:How-to_implement_TinyMCE_in_PHP

  • Tony, could you pass me your skype to assist me in a more integrated way? I’m having some problems yet... Hugs

1


0

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

//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!

}

Already for a PHP page I leave only one idea, you work it as well as you think best.. 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;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.