wysiwyg editor, how to pull the contents of the textarea and insert into the mysql database with php

Asked

Viewed 591 times

-1

I tried to pull the information contained in the textarea, ie the wysiwyg editor, with the text properly formatted and then include in the mysql database, what occurs at the moment is that it only pulls the information contained in the input.

the source files of the editor are also in:

https://github.com/suyati/line-control

Thanks in advance for the help and willingness !

Below is the corresponding HTML index.php:

<!DOCTYPE HTML>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
        <script src="editor.js"></script>
        <script>
            $(document).ready(function() {
               //esse é o script padrão para exibição do editor
                $("#txtEditor").Editor();

                //essa deveria ser a solução para uso via GET mais quando a utilizo o editor some..
                $("#txtEditor").Editor('getText');

            });
        </script>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
        <link href="editor.css" type="text/css" rel="stylesheet"/>
        <title>LineControl | v1.1.0</title>
    </head>
    <body>
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-10">
                    <form method="POST" action="?paginas=teste" name="form_redacao" id="form_redacao" onsubmit="return enviardados();" enctype="multipart/form-data" novalidate>
                        <label>Título</label>
                        <input class="form-control" type="text" placeholder="" id="titulo_from" name="titulo_from">

                        <label>Conteúdo</label>
                        <textarea id="txtEditor" name="txtEditor"></textarea>
                        <br>
                        <input type="submit" class="btn btn-default" id="btn-enviar" value="Mostrar Resultado">
                    </form>
                </div>
            </div>
        </div>
    </body>
</html>

And here the registration of the test.php content, as I mentioned before, only comes the content of Titulo, and I can insert it in mysql.

<?php

//if (isset($_POST['btn-enviar'])) {
    try{
        /*Pega as informações vindas do formulario*/

        $titulo_from = $_POST['titulo_from'];

        $redacao_from = $_POST['txtEditor'];

        /*executa a inclusão no banco de dados*/
        $inserir = $pdo->prepare("INSERT INTO conteudo (titulo_redacao, text_redacao) VALUES (:titulo_redacao, :text_redacao)");

        /*associa aos campos com o do formulario*/

        $inserir->bindValue(':titulo_redacao', $titulo_from);
        $inserir->bindValue(':text_redacao', $redacao_from);


        $inserir->execute();


        echo $titulo_from;
        echo "<br>";
        echo $redacao_from;

        var_dump($inserir);

        if ($inserir == true){
                echo "
                    <script language='javascript'>
                        window.alert('Mensagem enviada com sucesso.');
                        /*window.location = 'index.php?paginas=pagseguro_listar';*/
                    </script>
                    "; 
        }else{ 
                echo "
                    <script language='javascript'>
                        window.alert('Falha ao enviar sua menssagem.');
                        /*window.location = 'index.php?paginas=form_pag_cadastro';*/
                    </script>
                    "; 
        }



    }catch(PDOExcception $erro){
        echo $erro->getmessage();
    }
//}
?>

1 answer

0

There are some problems in your code, but to detect your error we need to see how far the text you type arrives, you have already tried to darum var_dump in $_POST before

        $inserir = $pdo->prepare("INSERT INTO conteudo (titulo_redacao, text_redacao) VALUES (:titulo_redacao, :text_redacao)");

Note that by accessing the $_Post glbal directly you are subject to some types of attack, even using bindvalue

  • so, in fact, there was no attempt to give a var_dump() before the $insert, but I just made that attempt.. var_dump($titulo_from,$redacao_from); what happens is that the second value the $redacao_form it already comes empty face... that is everything I type in the editor is ignored..

  • the worst is that the editor’s JS is not accusing any kind of error.. leaving me in the dark...

  • face if the value is not coming, you are probably putting some name in the textarea and looking for another name to play in the variable

  • I thought about it a while later, I redid the test taking that care. what runs it is that I can only get the value coming from the input, what comes from the editor always comes to me with length 0, that is null.

  • give me your form there, just the form

  • <method="POST" action="? paginas=teste" name="form_redacao" id="form_redacao" onsubmit="return enviardados();" enctype="multipart/form-data" novalidate>&#xA; <input class="form-control" type="text" placeholder="" id="titulo_from" name="titulo_from">&#xA; <textarea id="txtEditor" name="txtEditor"></textarea> <input type="Submit" class="btn btn-default" id="btn-submit" value="Show Result"> </form>

  • I believe your problem is this /if (isset($_POST['btn-send'])) {, the check code of the button is commented takes the comment and makes the code run only if the button click exists

  • in reality I put the comment in this line because he would not even display var_dump(); with it active.. and even with it active... The operation is the same... or just pulls the input data. those who see from the wysiwyg editor, do not see anything length=0 understood.? the command line $("#txtEditor"). Editor('gettext'); according to the documentation of it should solve this, more for some reason is not capturing the content..

Show 3 more comments

Browser other questions tagged

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