Add another ckeditor in codeigniter using add button on the page Add another ckeditor in codeigniter using add button on the page codeigniter codeigniter

Add another ckeditor in codeigniter using add button on the page


Unfortunately ckeditor plugin used to create dynamic id for editor panel. While appending div, plugin finds duplicate editor instances with same id textheading_lead[] and it was throwing error in your case. Here i made some alterations and will work for you.

<?phpdefined('BASEPATH') OR exit('No direct script access allowed');?><html lang="en">  <head>  <title>How to Integrate CKeditor in Codeigniter using Bootstrap</title>  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  <script type="text/javascript" src="<?php echo base_url(); ?>assets/ckeditor/ckeditor.js"></script>  <script type="text/javascript" src="<?php echo base_url(); ?>assets/ckfinder/ckfinder.js"></script></head><body><div class="container"><form method="post" action="<?php echo base_url(); ?>/Test57619322/here">    <div class="row">        <div class="col-lg-12">            <div id="addanother">                <br>                <?php echo $this->ckeditor->editor("textheading_lead[0]",""); ?>                <br>                <div class="form-group">                    <label for="sel1">小見出し</label>                    <select class="form-control" name="subheading[]">                        <option value="">監修 one</option>                        <option value="">監修 two</option>                        <option value="">監修 three</option>                        <option value="">監修 four</option>                    </select>                </div>                <input type="text" class="form-control" name="subheading_text[]">                            </div>            <div id="addnewdiv"></div>                    </div>            </div>    <div class="row" style="margin-top:20px;">        <div class="col-lg-12">            <a href="" class="btn btn-info addfields" >+ Add Fields</a>            <input type="submit" name="submitBtn" value="Submit" class="btn btn-success">        </div>    </div>      </form></div><script type="text/javascript">    $('.addfields').on('click', addfields);    var i=0;    function addfields(e) {      e.preventDefault();      var copy = $('#addanother').clone();      var oneplus=i+1;      $(copy).find('div#cke_textheading_lead\\[0\\]').remove();      $(copy).find('script').remove();      $(copy).find('textarea[name=textheading_lead\\[0\\]]').attr('name', 'textheading_lead['+oneplus+']');      $('#addnewdiv').append($(copy).html()+ '<br>');      CKEDITOR.replace('textheading_lead['+oneplus+']');      i++;      }</script></body></html>

You can receive response in your controller like $_POST["textheading_lead"] or Codeigniter post method and as usual it gets as an array.