How to get "name" in an HTML editor?

1

Ineedtosendtheinformationtypingintothedatabase,howeverIdonotknowhowtogettheinformationfromtheHTMLeditor.Hereisthecode:

<divclass="alinha">
    <h3>Sistema de notícias</h3>
    <form action="valida_noticia.php" method="post">
    <div class="form-group">
      <label>Título da notícia</label>
      <input type="text" name="titulonoticia" class="form-control" placeholder="Forneça o título da notícia">
    </div>
    <div class="form-group">
      <script src="https://cdn.ckeditor.com/4.7.3/standard/ckeditor.js"></script><textareaname="editor"></textarea>
      <script>
        CKEDITOR.replace( 'editor' );
      </script>
<!--       <div class="adjoined-bottom">
        <div class="grid-container">
          <textarea id='editor' name='editor'></textarea>
        </div>
      </div> -->
    </div>
    <button type="submit" class="btn btn-default">Enviar</button>
  </div>
</form>
    
asked by anonymous 25.10.2017 / 13:30

2 answers

2

1 - You can not put an editor in a div if you want to submit via form , you should put it in textarea :

<textarea id='editor' name='editor'></textarea>

2 - To leave recoverable instance, you need to start it:

<script>CKEDITOR.replace( 'editor' );</script>

Just done, just use the field like any other.

If you want to use AJAX to submit the form you should recover from the second form:

var data = CKEDITOR.instances.editor.getData();

Reference:

<script src="https://cdn.ckeditor.com/4.7.3/standard/ckeditor.js"></script><divclass="alinha">
    <h3>Sistema de notícias</h3>
      <form enctype="multipart/form-data"  action="valida_noticia.php" method="post">
         <div class="form-group">
           <label>Título da notícia</label>
           <input type="text" name="titulonoticia" class="form-control" placeholder="Forneça o título da notícia">
         </div>
         <div class="form-group">
           <textarea name="editor"></textarea>
         </div>
         <button type="submit" onclick="updateTexto()" class="btn btn-default">Enviar</button>
      </form>
<script>
   function updateTexto()
   {
    for (instance in CKEDITOR.instances) {
        CKEDITOR.instances[editor].updateElement();
        }
    }

   CKEDITOR.replace( 'editor' );
</script>

CKEditor Docs

    
25.10.2017 / 14:01
0

Complementing what @AntharixBR friend said, you should use a textarea to use CKEditor and use the instance for it to work. Already to retrieve the textarea data to submit the form, the methods are:

PHP

$nomedavariavel = $_POST['nomedatextarea'];

JS

var nomedavar = $('textarea[name=noemdatextarea]').val();

Any doubt just call friend!

    
26.10.2017 / 00:12