I finally decided that after 3 or 4 hours. It was easier than I thought, but not so elegant. This can be achieved with php and javascript to make it a bit more elegant, but plain old html and Javascript will also do the trick if you have few text fields.
First, HTML / PHP:
<h3 style='display:inline'>Chapter 1: </h3> <input style='display:inline' type="text" name="titlechapter_1" placeholder="Title chapter 1"><br><br> <textarea class="ckeditor" onChange="editing('Chapter 1');" name="chapter_1"></textarea> <?php for ($i=2; $i<=10; $i++) echo "<div id='div_editor_".$i."' style='display:none;'><textarea id='editor_".$i."' name='editor".$i."'></textarea></div>"; ?> <br><br> <input type="button" onclick="createEditor();" value=" Add chapter "> <br><br>
Understand that it creates all divs, but since there is nothing in them, they do not appear. Then, Javascript:
num_chapter = 2; var editor = new Array(); function createEditor() { if (num_chapter <= 10) { toggle_visibility('div_editor_' + num_chapter ); document.getElementById('div_editor_' + num_chapter).insertAdjacentHTML( "afterbegin", "<br><br><h3 style='display:inline'>Chapter " + num_chapter + ": </h3><input style='display:inline' type='text' name='titlechapter_" + num_chapter + "' placeholder='Title for chapter " + num_chapter + "'><br><br>");
This code will generate 10 chapters that work correctly with CKeditor. If the 11th attempt was created, a warning is displayed in a pop-up window. it is important that this string for ($i=1; $i<10; $i++) , this num_chapter < 10 and this num_chapter == 10 all have the same value (10 in my case).
source share