Ckeditor Fills data in URL when sending

Asked

Viewed 151 times

1

Good morning guys.

You’ve seen this problem using the Ckeditor?

I have a form where my text box <textarea></textarea> is replaced by the text editor Ckeditor.

I have it on my page:

<form class="panel input-group col-md-12" id="form_relatorio">
                    <textarea id="texto_relatorio" name="texto_relatorio" class="form-control" placeholder="Digite nesse espaço o Relatório de Serviço"></textarea>

                    <script>
                            CKEDITOR.replace( 'texto_relatorio', {  enterMode : CKEDITOR.ENTER_BR, shiftEnterMode : CKEDITOR.ENTER_BR } );
                             CKEDITOR.on( 'instanceReady', function( ev )
                            {
                             ev.editor.dataProcessor.writer.setRules( 'br',
                             {
                                indent : false,
                                breakBeforeOpen : false,
                                breakAfterOpen : false,
                                breakBeforeClose : false,
                                breakAfterClose : false
                             });
                        });

                    </script>
                    <div class="form-group row" >
                        <label for="data_relatorio" class="col-xs-3 col-form-label">Data do Chamado: </label>
                        <div class="col-xs-3">
                            <input class="form-control" type="date" id="data_relatorio" name="data_relatorio" value="<?php echo date("Y-m-d");?>">
                        </div>
                    </div>              
                    <div class="form-group row">
                        <label for="empresas" class="col-xs-3">Serviço Prestado à:</label>
                        <div class="col-xs-3">
                            <select class="form-control" type="search" name="empresas" id="empresas">    
                                <option value="Avulso">Avulso</option>                          
                                <option value="cliente1">Cliente 1</option>
                                <option value="cliente2">Cliente 2</option>
                                <option value="cliente3">Cliente 3</option>                                                         
                            </select>
                        </div>
                    </div>

                        <button class="btn btn-primary btn-block" id="btn_relatorio" type="submit">Enviar</button>                          

                </form>

And at the beginning of my page in my header.php file I have the form submission and opening of Ckeditor:

$('#btn_relatorio').click( function(){

        for(var instanceName in CKEDITOR.instances)
        CKEDITOR.instances[instanceName].updateElement();


        if($('#texto_relatorio').val(). length > 0){                
            $.ajax({
                url: 'inc/envia_relatorio.php',
                method: 'post',
                data: $('#form_relatorio').serialize(),
                sucess: function(data){                     
                    $('#texto_relatorio').val('');
                        atualizaRelatorio();
                        return false;                           
                }
            });
        }               

    });

He’s doing everything right. Sending it to my database, with all the right formatting. My problem is that every time I give Submit in the form, all my variables go to the URL, getting giant an example it looks like this: http://local.mentec.com.br/sistema/relatorios?texto_relatorio=teste&data_relatorio=2017-11-05&empresas=Avulso

Like I just sent it by GET. I believe that these data that are going are from textarea before the Ckeditor. Is there any way to "bar" this text to go to URL?

Because if I send a 2 or 3 forms then I already get error from a very extensive URL of my server and do not let me send the data, then I need to reload the page or clear the URL.

Thank you guys, hugs

1 answer

0

Oh leave it alone guys, I found a function that you can use in Ckeditor itself, Setdata('').

Thus remaining:

$('#btn_relatorio').click( function(){

        for(var instanceName in CKEDITOR.instances)
        CKEDITOR.instances[instanceName].updateElement();
        CKEDITOR.instances[instanceName].setData('');


        if($('#texto_relatorio').val(). length > 0){                
            $.ajax({
                url: 'inc/envia_relatorio.php',
                method: 'post',
                data: $('#form_relatorio').serialize(),
                sucess: function(data){                     
                    $('#texto_relatorio').val('');
                        atualizaRelatorio();
                        return false;                           
                }
            });
        }   return false;           

    });

That I replace my Button type from Submit to type="button" And I add one return false; at the end of my IF to clear the field and not to do Submit via URL.

Was worth O7

Browser other questions tagged

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