I cannot write tinyCME formatted text to the database

Asked

Viewed 517 times

1

The code without the text editor saves to the database. After I placed the editor, the form’s Submit button does not send data. I’m also interested in recording excerpts of programming codes. Below is the form code.

<?php
if(!isset($_SESSION)) { 
    session_start(); 
} 

if(empty($_SESSION['username'])){
    session_destroy();
    header('Location: index.php'); exit;
} 

include_once 'modules/crud_resposta.php';
?>

<html lang="pt-br">
<head>
  <?php include('templates/head_content.html.php'); ?>
  <title>Início</title>
</head>
<body>
<?php
?>
<?php include('templates/navbar.html.php'); ?>
    <?php include('templates/header.html.php'); ?>
        <script src="//tinymce.cachefly.net/4.2/tinymce.min.js"></script>
        <script>
            tinymce.init({selector:'textarea',
            plugins: 'code'});
        </script>
    <div class="row">
        <div class="col-lg-12">
            <h3 class="text-center">Responder Discussão</h3>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-8 col-lg-offset-2">
            <form method="post">
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-         form-group controls">
                            <label>Conteúdo:</label>
                            <textarea rows="5" class="form-control ckeditor" placeholder="resposta" name="conteudo" required data-validation-required-message="Favor, insira a resposta."></textarea>
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <br>
                    <div id="success"></div>
                    <div class="row">
                        <div class="form-group col-xs-12">
                            <button type="submit" name="inserir" class="btn btn-success btn-lg">Responder</button>
                            <button class="btn btn-danger btn-lg">Cancelar</button>
                        </div>
                    </div>
            </form>
        </div>
    </div>
</div>
    <?php
        include('templates/footer.html.php');
    ?>
 </body>
</html>

And below is the CRUD code snippet.

if(isset($_POST['inserir'])){
    $conteudo_resposta = trim($_POST['conteudo']);
    $conteudo = mysqli_real_escape_string($conexao, $conteudo_resposta);
    $data_criacao = date('Y-m-d H:i:s');
    $id_usuario = $_GET['usuario'];
    $id_discussao = $_GET['discussao'];

    $inserir_resposta = mysqli_prepare($conexao, "INSERT INTO resposta(conteudo, data_criacao, id_discussao, id_usuario) VALUES(?,?,?,?)");

    if($inserir_resposta){

        mysqli_stmt_bind_param($inserir_resposta, "ssii", $conteudo, $data_criacao, $id_discussao, $id_usuario);
        mysqli_stmt_execute($inserir_resposta);
        mysqli_stmt_close($inserir_resposta);

        ?>
  <script>return alert('Resposta inserida com sucesso!');</script>
  <?php
            header('Location:respostas.php?discussao=' .$id_discussao);
    }
    else{
                ?>
      <script>alert('Erro ao efetuar a resposta!');</script>
      <?php
                die(mysqli_error($conexao));
    }

    if(!$inserir_resposta){
        die(mysqli_error($conexao));
    }   
}
  • Luana, no error message is returned?

  • No, it does not return.

  • Try adding right after the first opening tag: <?php the code: error_reporting(E_ALL); ini_set('display_errors','On'); .

  • This error appeared in the element inspecter console: "An invalid form control with name='content' is not focusable."

  • I guess instead of a button you’d have to use input. Example: http://www.tinymce.com/wiki.php/TinyMCE3x:How-to_implement_TinyMCE_in_PHP and http://www.scriptbrasil.com.br/forum/topic/117385-tinymce/

  • I used the input and it still didn’t work.

  • 1

    I had to remove the required for it to work. So, I will have to validate the form with same javascript...

  • Just out of curiosity, already checked if the error occurs in browsers Chrome, firefox... Or only in one of them?

  • Error happened in Firefox too.

Show 4 more comments
No answers

Browser other questions tagged

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