<br><br>
        <div id="wrapper">

 
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <h5 class="modal-title" id="composemodalTitle">New Template</h5>
                                                            <button type="button"  onClick="history.back()" class="close" data-dismiss="modal" aria-label="Close">
                                                            <span aria-hidden="true">&times;</span>
                                                            </button>
                                                        </div>
                                                        <div class="modal-body p-3">
                                                            <form id="form">
                                                                <div class="form-group">
                                                                    <label for="name-input">Name</label>
                                                                    <input type="text" name="name" class="form-control" id="name" placeholder="Template Name" value='<?php if ($name) { echo $name; }?>' required>
                                                                </div>

                                                                <div class="form-group">
                                                                    <label for="messageto-input">Cc</label>
                                                                    <input type="email" name="to" class="form-control" id="email" placeholder="example@email.com" value='<?php if ($to) { echo $to; }?>' required>
                                                                </div>

                                                                <div class="form-group">
                                                                    <label for="subject-input">Subject</label>
                                                                    <input type="text" name="subject" class="form-control" id="subject" placeholder="your subject" value='<?php if ($subject) { echo $subject; }?>' required>
                                                                </div>

                                                                <div class="form-group">
                                                                    <label  for="subject-input">Message</label>
                                                                    <!-- basic summernote-->
                                                                    <div id="summernote-basic"></div>
                                                                </div>

                                                            </form>
                                                        <!-- ------- -->
                                                        <div class="modal-body" style="width: 50%;padding: 0rem !important;">
                                                            <table class="table table-dark table-borderless mb-0">
                                                            <thead>
                                                            <tr>
                                                                <th>Field Name</th>
                                                                <th>HTML Name</th>
                                                            </tr>
                                                            </thead>
                                                            <tbody>
                                                            <?php foreach ($dropdownData as $key => $value) { ?>
                                                            <tr>
                                                                <td><?php echo $value['name']; ?></td>
                                                                <td><?php echo $value['variable_name']; ?></td>
                                                            </tr>
                                                            <?php } ?>
                                                            </tbody>
                                                            </table>
                                                        </div>
                                                        <!-- ------- -->
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button type="button" class="btn btn-light" onClick="history.back()" data-dismiss="modal">Close</button>
                                                            <button type="button" id="data" class="btn btn-primary">Save <i class="fab fa-telegram-plane ml-1"></i></button>
                                                        </div>
                                                    </div>
                                        
        </div>
        <!-- /Right-bar -->
        <input type="hidden" id="id" value='<?php if ($id) { echo $id; }?>'>
        <input type="hidden" id="hid" value='<?php if ($code) { echo $code; }?>'>

        <!-- Right bar overlay-->
        <div class="rightbar-overlay"></div>

    </body>
<script>
if ($('#hid').val().length != 0) 
{
    setTimeout(() => 
      {
        $('.note-placeholder').html('');
        $('.note-editable > p:first').html($('#hid').val());
      }, 500);
}

$(document).on('click','#data',function(){
    $('.btn-codeview').click();
    var URL;
    var DATA;
    if ($('#hid').val().length == 0) {
    URL = "<?php echo base_url();?>email_temp";
    DATA = { 
        'name' : $('#name').val() , 
        'to' : $('#email').val() , 
        'subject' : $('#subject').val() , 
        'text' : $('.note-editable  > p:first').text() , 
        'code' : $('.note-codable').val() 
    };
    }
    else {
    URL = "<?php echo base_url();?>edit_email_temp/1";
    DATA = { 
        'id' : $('#id').val(),
        'name' : $('#name').val(), 
        'to' : $('#email').val(), 
        'subject' : $('#subject').val(), 
        'text' : $('.note-editable  > p:first').text(), 
        'code' : $('.note-codable').val() 
    };
    }
    $.ajax({ 
      type: "post",
      url: URL,
      data: DATA,
      json: true,
      success: function(response) {
        if (response == true) 
        {
            window.location = "<?php echo base_url();?>template_list";
        } 
      },
      error: function(jqXHR, textStatus, err) { alert('text status '+textStatus+', err '+err) }
    });
});


// var data = $('#form').serialize();
// console.log($('.note-editable').text()); // text
// console.log($('.note-codable').val()); //code
</script>
</html>