how to define ck-editor with id or class

7.8k views Asked by At

My php file like this i am useing ck-editor in condition if i got $status > 0 than at that time display ck-editor otherwise it's display text box the problem is when my ck-editor name and text box name is same because i want to insert only one value which i get in post so i want to specify my ck-editor with id or class so i can get proper display and output

<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      Settings
      <small>Settings Edit</small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
      <li class="active">Settings Edit</li>
    </ol>
  </section>
  <!-- Main content -->
  <section class="content">
    <!-- Default box -->
    <div class="box">
        <div class="box box-primary">
          <!-- form start -->
          <form role="form" action="settingsedit.php" method="POST">
            <input type="hidden" name="settings_id" value="<?php echo $settings_id; ?>">
            <input type="hidden" name="settings_id" value="<?php echo $status; ?>">
            <div class="box-body">
              <div class="form-group">
                <label for="exampleInputEmail1">Phone Number</label>
                <?php 

                     if($status > 0) 
                     {
                        echo '<textarea name="settings" required>'.$value.'</textarea>';
                      }
                      else
                      {
                        echo '<input type="text" value="'.$value.'" name="settings">';
                      }
                  ?>
              </div>
                <div class="box-footer">
                <input type="submit" name="submit" class="btn btn-primary">
            </div>
          </form>
    </div><!-- /.box-body -->
  </section><!-- /.content -->
</div><!-- /.content-wrapper -->
<?php include 'footer.php'; ?>
<script src="//cdn.ckeditor.com/4.4.7/standard/ckeditor.js"></script>
<script>CKEDITOR.replace('settings');</script>
2

There are 2 answers

0
n00dl3 On BEST ANSWER

CKEditor docs says the replace method takes an element argument :

element : Object/String The DOM element (textarea), its ID, or name.

So, you can use document.getElementById to select your textarea and then use CKEditor.replace upon it.

php/HTML :

<textarea id="mytextarea" name="settings" required><?php echo $value;?></textarea>

JS:

var textarea = document.getElementById('mytextarea');
CKEditor.replace(textarea);
0
AudioBubble On

i got my answer simply give class of ckeditor and give id to that textarea and add that class in to ckeditor..

<textarea name="settings" class="ckeditor" id="test" required>'.$value.'</textarea>
<script>CKEDITOR.replace('#test');</script>