Disable Textarea (with TinyMCE) when loading mysql data

0

To disable a textarea with tinyMCE I used the

tinyMCE.get('id_textarea').getBody().setAttribute('contenteditable', false);

Inside a Javascript script, with an onclick event of a button, and everything went well.

The problem now is this: I have 5 pages, each page with 5 textareas, all editable by tinyMCE, and with a "Save" button for each textarea. On the last page, I inserted a "Submit" submit button, which writes a "yes" to BD mysql, a table with the textarea and the "sent" field that receives this "yes". What I'm trying to do and can not do is, after clicking on this submit button "Send", that all textarea are disabled for editing, through an SQL query to the field "sent", ie after the "yes" the user can not edit textarea anymore, nor at that time, nor after reopening pages with textarea.

I have already inserted the script in the <head> tag, I already tried to put the script in an echo within php, and nothing was good enough to disable it, it only writes the sim in the DB. Here is the script and php / html code. Inside the <head> tag:

function enviartudo() {            
  tinyMCE.get('id_textarea1').getBody().setAttribute('contenteditable', false);            
  tinyMCE.get('id_textarea2').getBody().setAttribute('contenteditable', false);
}

PHP

After a SELECT to DB:

include_once('conexao.php');
$query = "SELECT..........";
$data = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($data);
if ($row['enviado'] == 'sim') {
    echo '<script type="text/javascript">
             enviartudo();
          </script>';
}

if (isset($_POST['enviar'])) {
    $query1 = "UPDATE tabela SET enviado = 'sim' ";
    $data1 = mysqli_query($dbc, $query1);
    mysqli_close($dbc);
 }

HTML

<tr>
    <td>
       <label>TEXTAREA 1</label>
       <textarea type="text" id="textarea1" name="textarea1" class="areatexto"
       maxlength="5000">
          <?php echo (isset($_POST['textarea1']) ? $_POST['textarea1'] : 
          htmlspecialchars_decode(stripslashes($row['textarea1']))); ?>
       </textarea>
       <input type="submit" name="submit1-1" value="Salvar" class="btn_save_item"/>
    </td>
</tr>
<tr>
    <td><br />
       <label>TEXTAREA 2</label>
       <textarea type="text" id="textarea2" name="textarea2" class="areatexto" maxlength="8000">
          <?php echo (isset($_POST['textarea2']) ? $_POST['textarea2'] : 
          htmlspecialchars_decode(stripslashes($row['textarea2']))); ?>
       </textarea>
       <input type="submit" name="submit1-2" value="Salvar" class="btn_save_item" />
    </td>
</tr>
<tr>
   <td>
      <input type="submit" name="enviar" value="Enviar" class="btn_save_item" />
   </td>
</tr>

I did not put all the 5 page code with the 5 textarea of each one, because it would be very large, but the code is repetitive, changing just id / name of div, form, textarea, submit buttons, p>     

asked by anonymous 26.07.2018 / 03:03

1 answer

0

As I mentioned above, after a good night's sleep I found a solution.

I created another tinymce script, however I changed the name of the Selector and I inserted readonly = 1, menubar = false and left only the preview on the toolbar, all to avoid editing. I created another skin tb (to change the background of the textarea). In PHP, I made an if / else, creating a variable that defines the class of the textarea. And in the HTML code, in the textarea, I inserted a class with PHP. Here are the codes:

Tinymce script 1:

tinymce.init ({
        selector: '.areatexto',
        height: 200,
        skin: 'custom',
        theme: 'modern',
        resize: false,
        plugins: 'print charwordcount preview searchreplace autolink visualblocks visualchars image link media table charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists textcolor imagetools contextmenu colorpicker textpattern',
        toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify  | numlist bullist outdent indent  | removeformat | table image | preview',});

I created another tinymce script:

tinymce.init ({
        selector: '.areatexto2', //aplica o plugin em todos textarea com class="areatexto2"
        height: 200, //altura de cada textarea
        skin: 'custom2',
        theme: 'modern',
        readonly: 1,
        resize: false,
        plugins: 'preview',
        toolbar1: 'preview',
        menubar: false, });

I created an if / else in PHP:

if ($row['enviado'] == 'sim') { $classTextarea = "areatexto2"; } else { $classTextarea = "areatexto"; }

And in HTML:

<textarea type="text" id="xxxxxx" name="xxxxx" class="<?php echo $classTextarea; ?>" maxlength="5000">

It works perfectly, no longer allowing editing of textarea (with class="areatexto2"), since readonly = 1, in addition to removing the menubar and all editing plugins.

    
26.07.2018 / 23:46