0
To disable a textarea with tinymce I used the code
tinyMCE.get('id_textarea').getBody().setAttribute('contenteditable', false);
within a Javascript script, with an onclick event of a button, and it happened all right.
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 "Send" Submit button, which saves a "yes" in the mysql BD, in a table with the textarea and with the "sent" field that receives that "yes". What I’m trying to do and I can’t, is, after clicking this "Submit" Submit button, that all textarea are disabled for editing, through an SQL query to the "sent" field, that is, after saving the "yes", the user can’t edit the textarea anymore, neither at that time, nor after reopening pages with textarea.
I already inserted the script in the tag <head>
, I tried to put the script in an echo inside php, and nothing helped to disable it, just save the yes in the BD. Follow the script and php/html code. Inside the tag <head>
:
function enviartudo() {
tinyMCE.get('id_textarea1').getBody().setAttribute('contenteditable', false);
tinyMCE.get('id_textarea2').getBody().setAttribute('contenteditable', false);
}
PHP
After a SELECT to the BD:
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 code of the 5 pages with the 5 textarea of each one, because it would be too big, but the code is repetitive, changing only id/name of div, form, textarea, Submit buttons, among others.
if ($row['enviado'] == 'sim') { $desabilitado = "disabled";
and in the textareas<textarea type="text" ..... maxlength="5000" <?php echo $desabilitado ?>>
– user60252
@Leocaracciolo, had already tried this, but the tinymce does not accept the "disabled", nor the "readonly" in the textarea. If I put readonly:1 in the tinymce setup, all textareas already start readonly when loading, and that’s not what I want. Anyway, thanks, but the problem remains..
– Blackhawk
Guys, I found a solution. I created another tinymce script, but changing the name of the Selector and another skin (to change the background of the textarea), and insert readonly=1. Then, in PHP, I made an if/Else, creating a variable that defines the textarea class. And in HTML code, in textarea, I inserted a class with PHP:
class="<?php echo $variavel; ?>"
. I’ll put the solution down..– Blackhawk