Codeigniter Bootstrap Markdown textarea





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am having issues implementing Bootstrap Markdown in Codeignitor 3.1.9.
I get it to pass and display data from a query in a view just fine as long as its a simple in form_input(). An issue arises when I attempt to post data from a form_textarea() wired up to Bootstrap Markdown with an id="bs-markdown"



Here is a partial of the view:



                    <div class="card-body"> 
<?php echo form_open(site_url("admin/edit_user/".$user->id."/"));?>
<div class="form-row">
<div class="form-group col-md-4">
<?php echo lang('edit_user_fname_label', 'first_name', array('class' => 'form-label'));?>
<?php echo form_input($first_name, 'first_name' , array('class' => 'form-control', 'id' => 'first_name'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_lname_label', 'last_name', array('class' => 'form-label'));?>
<?php echo form_input($last_name, 'last_name' , array('class' => 'form-control', 'id' => 'last_name'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_company_label', 'company', array('class' => 'form-label'));?>
<?php echo form_input($company, 'comnpany' , array('class' => 'form-control', 'id' => 'company'));?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<?php echo lang('edit_user_vat_label', 'vat', array('class' => 'form-label'));?>
<?php echo form_input($vat, 'vat' , array('class' => 'form-control', 'id' => 'vat'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_email_label', 'email', array('class' => 'form-label'));?>
<?php echo form_input($email, 'email' , array('class' => 'form-control', 'id' => 'email'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_phone_label', 'phone', array('class' => 'form-label'));?>
<?php echo form_input($phone, 'phone' , array('class' => 'form-control', 'id' => 'phone'));?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12"">
<label class="form-label">Status</label>
<select class="custom-select">
<option selected="">Active</option>
<option>Suspended</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-8 col-lg-12 col-xl-6">
<h6 class="card-header">Notes on Customer</h6>
<div class="card-body py-0 px-0">
<?php echo form_textarea('notes',$notes, array('id' => 'bs-markdown'));?>
</div>
</div>
</div>
</div>
<?php echo form_hidden('id', $user->id);?>
<?php echo form_hidden($csrf); ?>
<div class="text-right mt-3">
<input type="submit" name="submit" value="Update" class="btn btn-primary">
</div>

<?php echo form_close();?>
</div>
<!-- / Content -->

<script>
// Bootstrap Markdown
$(function() {
$('#bs-markdown').markdown({
iconlibrary: 'fa',
footer: '<div id="md-character-footer"></div><small id="md-character-counter" class="text-muted">600 character left</small>',

onChange: function(e) {
var contentLength = e.getContent().length;

if (contentLength > 600) {
$('#md-character-counter')
.removeClass('text-muted')
.addClass('text-danger')
.html((contentLength - 600) + ' character surplus.');
} else {
$('#md-character-counter')
.removeClass('text-danger')
.addClass('text-muted')
.html((600 - contentLength) + ' character left.');
}
},
});

// Update character counter
$('#markdown').trigger('change');


// *******************************************************************
// Fix icons

$('.md-editor .fa-header').removeClass('fa fa-header').addClass('fas fa-heading');
$('.md-editor .fa-picture-o').removeClass('fa fa-picture-o').addClass('far fa-image');
});
</script>


Here is the controller:



/**
* Edit a user
*
* @param int|string $id
*/
public function edit_user($id)
{
// Retrieves the operating Users data as Object wich is passed to _navbar
$this->data['operator'] = $this->ion_auth->user()->row();

$user = $this->ion_auth->user($id)->row();

// validate form input
$this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'trim|required');
$this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'trim|required');
$this->form_validation->set_rules('phone', $this->lang->line('edit_user_validation_phone_label'), 'trim|required');
$this->form_validation->set_rules('email', $this->lang->line('edit_user_validation_email_label'), 'trim|required');

if (isset($_POST) && !empty($_POST))
{

// do we have a valid request?
if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id'))
{
show_error($this->lang->line('error_csrf'));
}

if ($this->form_validation->run() === TRUE)
{


//echo var_dump($_POST);
//exit();

$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'company' => $this->input->post('company'),
'phone' => $this->input->post('phone'),
'email' => $this->input->post('email'),
'notes' => $this->input->post('bs'),


);


// check to see if we are updating the user
if ($this->ion_auth->update($user->id, $data))
{
// redirect them back to the admin page if admin, or to the base url if non admin
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('admin/edit_user/'.$id, 'refresh');

}
else
{
// redirect them back to the admin page if admin, or to the base url if non admin
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('admin/edit_user/'.$id, 'refresh');

}

}
}

// set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));

// pass the user to the view
$this->data['user'] = $user;

$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'value' => $this->form_validation->set_value('first_name', $user->first_name),

);
$this->data['last_name'] = array(
'name' => 'last_name',
'id' => 'last_name',
'type' => 'text',
'value' => $this->form_validation->set_value('last_name', $user->last_name),
);
$this->data['company'] = array(
'name' => 'company',
'id' => 'company',
'type' => 'text',
'value' => $this->form_validation->set_value('company', $user->company),
);
$this->data['vat'] = array(
'name' => 'vat',
'id' => 'vat',
'type' => 'text',
'value' => $this->form_validation->set_value('vat', $user->vat),
);
$this->data['email'] = array(
'name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email', $user->email),
);
$this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'type' => 'text',
'value' => $this->form_validation->set_value('phone', $user->phone),
);

$this->data['notes'] = $user->notes;

// display the edit user form
$this->data['csrf'] = $this->_get_csrf_nonce();


// VIEW: PARTIALS & TEMPLATE
$partials['_dev_bar'] = $this->load->view('_dev_bar', NULL, TRUE);
$partials['navbar'] = $this->load->view('admin/modules/_navbar', $this->data, TRUE);
$partials['sidenav'] = $this->load->view('admin/modules/_sidenav', NULL, TRUE);
$partials['content'] = $this->load->view('admin/modules/_body-user-customer-edit', NULL, TRUE);
$partials['bottomnav'] = $this->load->view('admin/modules/_bottomnav', NULL, TRUE);
$this->load->view('admin/_admin-template', $partials);
}


/**
* @return array A CSRF key-value pair
*/
public function _get_csrf_nonce()
{
$this->load->helper('string');
$key = random_string('alnum', 8);
$value = random_string('alnum', 20);
$this->session->set_flashdata('csrfkey', $key);
$this->session->set_flashdata('csrfvalue', $value);

return array($key => $value);
}

/**
* @return bool Whether the posted CSRF token matches
*/
public function _valid_csrf_nonce(){
$csrfkey = $this->input->post($this->session->flashdata('csrfkey'));
if ($csrfkey && $csrfkey === $this->session->flashdata('csrfvalue')){
return TRUE;
}
return FALSE;
}

public function redirectUser(){
if ($this->ion_auth->is_admin()){
redirect('admin', 'refresh');
}
redirect('/', 'refresh');
}


A var_dump($Post) reveals that notes is not even posted to the array:



array(9) { 
["first_name"]=> string(7) "Johnwww"
["last_name"]=> string(5) "Ddddd"
["company"]=> string(0) ""
["vat"]=> string(0) ""
["email"]=> string(12) "john@doe.com"
["phone"]=> string(8) "07009090"
["id"]=> string(1) "3"
["91EnDeLb"]=> string(20) "0ibAqJsuo9mkVzKlRrEy"
["submit"]=> string(6) "Update"
}


If I omit referencing bootsrap markdown as an id="bs-markdown" in the textarea of the view them the var_dump() includes the item ["notes"]=> string(5) "notes"



Any pointer on how to proceed would be appreciated.










share|improve this question























  • fyi codeigniter has it's own CSRF system that is pretty good. anyways if this plugin is anything like CKeditor or the like, the contents aren't posted by default and can be gotten via some function. This usually makes it easy for ajax, but a pain for regulator posting. I'm not sure how you would do it in this plugin. However as doesn't seem to be actively maintained I would switch to something like CK, tinymce, or my favorite - summernote

    – Alex
    Nov 17 '18 at 2:36











  • I did end up using summernote, with success. Thank you.

    – Marcus
    Nov 17 '18 at 13:07


















0















I am having issues implementing Bootstrap Markdown in Codeignitor 3.1.9.
I get it to pass and display data from a query in a view just fine as long as its a simple in form_input(). An issue arises when I attempt to post data from a form_textarea() wired up to Bootstrap Markdown with an id="bs-markdown"



Here is a partial of the view:



                    <div class="card-body"> 
<?php echo form_open(site_url("admin/edit_user/".$user->id."/"));?>
<div class="form-row">
<div class="form-group col-md-4">
<?php echo lang('edit_user_fname_label', 'first_name', array('class' => 'form-label'));?>
<?php echo form_input($first_name, 'first_name' , array('class' => 'form-control', 'id' => 'first_name'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_lname_label', 'last_name', array('class' => 'form-label'));?>
<?php echo form_input($last_name, 'last_name' , array('class' => 'form-control', 'id' => 'last_name'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_company_label', 'company', array('class' => 'form-label'));?>
<?php echo form_input($company, 'comnpany' , array('class' => 'form-control', 'id' => 'company'));?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<?php echo lang('edit_user_vat_label', 'vat', array('class' => 'form-label'));?>
<?php echo form_input($vat, 'vat' , array('class' => 'form-control', 'id' => 'vat'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_email_label', 'email', array('class' => 'form-label'));?>
<?php echo form_input($email, 'email' , array('class' => 'form-control', 'id' => 'email'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_phone_label', 'phone', array('class' => 'form-label'));?>
<?php echo form_input($phone, 'phone' , array('class' => 'form-control', 'id' => 'phone'));?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12"">
<label class="form-label">Status</label>
<select class="custom-select">
<option selected="">Active</option>
<option>Suspended</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-8 col-lg-12 col-xl-6">
<h6 class="card-header">Notes on Customer</h6>
<div class="card-body py-0 px-0">
<?php echo form_textarea('notes',$notes, array('id' => 'bs-markdown'));?>
</div>
</div>
</div>
</div>
<?php echo form_hidden('id', $user->id);?>
<?php echo form_hidden($csrf); ?>
<div class="text-right mt-3">
<input type="submit" name="submit" value="Update" class="btn btn-primary">
</div>

<?php echo form_close();?>
</div>
<!-- / Content -->

<script>
// Bootstrap Markdown
$(function() {
$('#bs-markdown').markdown({
iconlibrary: 'fa',
footer: '<div id="md-character-footer"></div><small id="md-character-counter" class="text-muted">600 character left</small>',

onChange: function(e) {
var contentLength = e.getContent().length;

if (contentLength > 600) {
$('#md-character-counter')
.removeClass('text-muted')
.addClass('text-danger')
.html((contentLength - 600) + ' character surplus.');
} else {
$('#md-character-counter')
.removeClass('text-danger')
.addClass('text-muted')
.html((600 - contentLength) + ' character left.');
}
},
});

// Update character counter
$('#markdown').trigger('change');


// *******************************************************************
// Fix icons

$('.md-editor .fa-header').removeClass('fa fa-header').addClass('fas fa-heading');
$('.md-editor .fa-picture-o').removeClass('fa fa-picture-o').addClass('far fa-image');
});
</script>


Here is the controller:



/**
* Edit a user
*
* @param int|string $id
*/
public function edit_user($id)
{
// Retrieves the operating Users data as Object wich is passed to _navbar
$this->data['operator'] = $this->ion_auth->user()->row();

$user = $this->ion_auth->user($id)->row();

// validate form input
$this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'trim|required');
$this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'trim|required');
$this->form_validation->set_rules('phone', $this->lang->line('edit_user_validation_phone_label'), 'trim|required');
$this->form_validation->set_rules('email', $this->lang->line('edit_user_validation_email_label'), 'trim|required');

if (isset($_POST) && !empty($_POST))
{

// do we have a valid request?
if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id'))
{
show_error($this->lang->line('error_csrf'));
}

if ($this->form_validation->run() === TRUE)
{


//echo var_dump($_POST);
//exit();

$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'company' => $this->input->post('company'),
'phone' => $this->input->post('phone'),
'email' => $this->input->post('email'),
'notes' => $this->input->post('bs'),


);


// check to see if we are updating the user
if ($this->ion_auth->update($user->id, $data))
{
// redirect them back to the admin page if admin, or to the base url if non admin
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('admin/edit_user/'.$id, 'refresh');

}
else
{
// redirect them back to the admin page if admin, or to the base url if non admin
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('admin/edit_user/'.$id, 'refresh');

}

}
}

// set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));

// pass the user to the view
$this->data['user'] = $user;

$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'value' => $this->form_validation->set_value('first_name', $user->first_name),

);
$this->data['last_name'] = array(
'name' => 'last_name',
'id' => 'last_name',
'type' => 'text',
'value' => $this->form_validation->set_value('last_name', $user->last_name),
);
$this->data['company'] = array(
'name' => 'company',
'id' => 'company',
'type' => 'text',
'value' => $this->form_validation->set_value('company', $user->company),
);
$this->data['vat'] = array(
'name' => 'vat',
'id' => 'vat',
'type' => 'text',
'value' => $this->form_validation->set_value('vat', $user->vat),
);
$this->data['email'] = array(
'name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email', $user->email),
);
$this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'type' => 'text',
'value' => $this->form_validation->set_value('phone', $user->phone),
);

$this->data['notes'] = $user->notes;

// display the edit user form
$this->data['csrf'] = $this->_get_csrf_nonce();


// VIEW: PARTIALS & TEMPLATE
$partials['_dev_bar'] = $this->load->view('_dev_bar', NULL, TRUE);
$partials['navbar'] = $this->load->view('admin/modules/_navbar', $this->data, TRUE);
$partials['sidenav'] = $this->load->view('admin/modules/_sidenav', NULL, TRUE);
$partials['content'] = $this->load->view('admin/modules/_body-user-customer-edit', NULL, TRUE);
$partials['bottomnav'] = $this->load->view('admin/modules/_bottomnav', NULL, TRUE);
$this->load->view('admin/_admin-template', $partials);
}


/**
* @return array A CSRF key-value pair
*/
public function _get_csrf_nonce()
{
$this->load->helper('string');
$key = random_string('alnum', 8);
$value = random_string('alnum', 20);
$this->session->set_flashdata('csrfkey', $key);
$this->session->set_flashdata('csrfvalue', $value);

return array($key => $value);
}

/**
* @return bool Whether the posted CSRF token matches
*/
public function _valid_csrf_nonce(){
$csrfkey = $this->input->post($this->session->flashdata('csrfkey'));
if ($csrfkey && $csrfkey === $this->session->flashdata('csrfvalue')){
return TRUE;
}
return FALSE;
}

public function redirectUser(){
if ($this->ion_auth->is_admin()){
redirect('admin', 'refresh');
}
redirect('/', 'refresh');
}


A var_dump($Post) reveals that notes is not even posted to the array:



array(9) { 
["first_name"]=> string(7) "Johnwww"
["last_name"]=> string(5) "Ddddd"
["company"]=> string(0) ""
["vat"]=> string(0) ""
["email"]=> string(12) "john@doe.com"
["phone"]=> string(8) "07009090"
["id"]=> string(1) "3"
["91EnDeLb"]=> string(20) "0ibAqJsuo9mkVzKlRrEy"
["submit"]=> string(6) "Update"
}


If I omit referencing bootsrap markdown as an id="bs-markdown" in the textarea of the view them the var_dump() includes the item ["notes"]=> string(5) "notes"



Any pointer on how to proceed would be appreciated.










share|improve this question























  • fyi codeigniter has it's own CSRF system that is pretty good. anyways if this plugin is anything like CKeditor or the like, the contents aren't posted by default and can be gotten via some function. This usually makes it easy for ajax, but a pain for regulator posting. I'm not sure how you would do it in this plugin. However as doesn't seem to be actively maintained I would switch to something like CK, tinymce, or my favorite - summernote

    – Alex
    Nov 17 '18 at 2:36











  • I did end up using summernote, with success. Thank you.

    – Marcus
    Nov 17 '18 at 13:07














0












0








0








I am having issues implementing Bootstrap Markdown in Codeignitor 3.1.9.
I get it to pass and display data from a query in a view just fine as long as its a simple in form_input(). An issue arises when I attempt to post data from a form_textarea() wired up to Bootstrap Markdown with an id="bs-markdown"



Here is a partial of the view:



                    <div class="card-body"> 
<?php echo form_open(site_url("admin/edit_user/".$user->id."/"));?>
<div class="form-row">
<div class="form-group col-md-4">
<?php echo lang('edit_user_fname_label', 'first_name', array('class' => 'form-label'));?>
<?php echo form_input($first_name, 'first_name' , array('class' => 'form-control', 'id' => 'first_name'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_lname_label', 'last_name', array('class' => 'form-label'));?>
<?php echo form_input($last_name, 'last_name' , array('class' => 'form-control', 'id' => 'last_name'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_company_label', 'company', array('class' => 'form-label'));?>
<?php echo form_input($company, 'comnpany' , array('class' => 'form-control', 'id' => 'company'));?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<?php echo lang('edit_user_vat_label', 'vat', array('class' => 'form-label'));?>
<?php echo form_input($vat, 'vat' , array('class' => 'form-control', 'id' => 'vat'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_email_label', 'email', array('class' => 'form-label'));?>
<?php echo form_input($email, 'email' , array('class' => 'form-control', 'id' => 'email'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_phone_label', 'phone', array('class' => 'form-label'));?>
<?php echo form_input($phone, 'phone' , array('class' => 'form-control', 'id' => 'phone'));?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12"">
<label class="form-label">Status</label>
<select class="custom-select">
<option selected="">Active</option>
<option>Suspended</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-8 col-lg-12 col-xl-6">
<h6 class="card-header">Notes on Customer</h6>
<div class="card-body py-0 px-0">
<?php echo form_textarea('notes',$notes, array('id' => 'bs-markdown'));?>
</div>
</div>
</div>
</div>
<?php echo form_hidden('id', $user->id);?>
<?php echo form_hidden($csrf); ?>
<div class="text-right mt-3">
<input type="submit" name="submit" value="Update" class="btn btn-primary">
</div>

<?php echo form_close();?>
</div>
<!-- / Content -->

<script>
// Bootstrap Markdown
$(function() {
$('#bs-markdown').markdown({
iconlibrary: 'fa',
footer: '<div id="md-character-footer"></div><small id="md-character-counter" class="text-muted">600 character left</small>',

onChange: function(e) {
var contentLength = e.getContent().length;

if (contentLength > 600) {
$('#md-character-counter')
.removeClass('text-muted')
.addClass('text-danger')
.html((contentLength - 600) + ' character surplus.');
} else {
$('#md-character-counter')
.removeClass('text-danger')
.addClass('text-muted')
.html((600 - contentLength) + ' character left.');
}
},
});

// Update character counter
$('#markdown').trigger('change');


// *******************************************************************
// Fix icons

$('.md-editor .fa-header').removeClass('fa fa-header').addClass('fas fa-heading');
$('.md-editor .fa-picture-o').removeClass('fa fa-picture-o').addClass('far fa-image');
});
</script>


Here is the controller:



/**
* Edit a user
*
* @param int|string $id
*/
public function edit_user($id)
{
// Retrieves the operating Users data as Object wich is passed to _navbar
$this->data['operator'] = $this->ion_auth->user()->row();

$user = $this->ion_auth->user($id)->row();

// validate form input
$this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'trim|required');
$this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'trim|required');
$this->form_validation->set_rules('phone', $this->lang->line('edit_user_validation_phone_label'), 'trim|required');
$this->form_validation->set_rules('email', $this->lang->line('edit_user_validation_email_label'), 'trim|required');

if (isset($_POST) && !empty($_POST))
{

// do we have a valid request?
if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id'))
{
show_error($this->lang->line('error_csrf'));
}

if ($this->form_validation->run() === TRUE)
{


//echo var_dump($_POST);
//exit();

$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'company' => $this->input->post('company'),
'phone' => $this->input->post('phone'),
'email' => $this->input->post('email'),
'notes' => $this->input->post('bs'),


);


// check to see if we are updating the user
if ($this->ion_auth->update($user->id, $data))
{
// redirect them back to the admin page if admin, or to the base url if non admin
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('admin/edit_user/'.$id, 'refresh');

}
else
{
// redirect them back to the admin page if admin, or to the base url if non admin
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('admin/edit_user/'.$id, 'refresh');

}

}
}

// set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));

// pass the user to the view
$this->data['user'] = $user;

$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'value' => $this->form_validation->set_value('first_name', $user->first_name),

);
$this->data['last_name'] = array(
'name' => 'last_name',
'id' => 'last_name',
'type' => 'text',
'value' => $this->form_validation->set_value('last_name', $user->last_name),
);
$this->data['company'] = array(
'name' => 'company',
'id' => 'company',
'type' => 'text',
'value' => $this->form_validation->set_value('company', $user->company),
);
$this->data['vat'] = array(
'name' => 'vat',
'id' => 'vat',
'type' => 'text',
'value' => $this->form_validation->set_value('vat', $user->vat),
);
$this->data['email'] = array(
'name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email', $user->email),
);
$this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'type' => 'text',
'value' => $this->form_validation->set_value('phone', $user->phone),
);

$this->data['notes'] = $user->notes;

// display the edit user form
$this->data['csrf'] = $this->_get_csrf_nonce();


// VIEW: PARTIALS & TEMPLATE
$partials['_dev_bar'] = $this->load->view('_dev_bar', NULL, TRUE);
$partials['navbar'] = $this->load->view('admin/modules/_navbar', $this->data, TRUE);
$partials['sidenav'] = $this->load->view('admin/modules/_sidenav', NULL, TRUE);
$partials['content'] = $this->load->view('admin/modules/_body-user-customer-edit', NULL, TRUE);
$partials['bottomnav'] = $this->load->view('admin/modules/_bottomnav', NULL, TRUE);
$this->load->view('admin/_admin-template', $partials);
}


/**
* @return array A CSRF key-value pair
*/
public function _get_csrf_nonce()
{
$this->load->helper('string');
$key = random_string('alnum', 8);
$value = random_string('alnum', 20);
$this->session->set_flashdata('csrfkey', $key);
$this->session->set_flashdata('csrfvalue', $value);

return array($key => $value);
}

/**
* @return bool Whether the posted CSRF token matches
*/
public function _valid_csrf_nonce(){
$csrfkey = $this->input->post($this->session->flashdata('csrfkey'));
if ($csrfkey && $csrfkey === $this->session->flashdata('csrfvalue')){
return TRUE;
}
return FALSE;
}

public function redirectUser(){
if ($this->ion_auth->is_admin()){
redirect('admin', 'refresh');
}
redirect('/', 'refresh');
}


A var_dump($Post) reveals that notes is not even posted to the array:



array(9) { 
["first_name"]=> string(7) "Johnwww"
["last_name"]=> string(5) "Ddddd"
["company"]=> string(0) ""
["vat"]=> string(0) ""
["email"]=> string(12) "john@doe.com"
["phone"]=> string(8) "07009090"
["id"]=> string(1) "3"
["91EnDeLb"]=> string(20) "0ibAqJsuo9mkVzKlRrEy"
["submit"]=> string(6) "Update"
}


If I omit referencing bootsrap markdown as an id="bs-markdown" in the textarea of the view them the var_dump() includes the item ["notes"]=> string(5) "notes"



Any pointer on how to proceed would be appreciated.










share|improve this question














I am having issues implementing Bootstrap Markdown in Codeignitor 3.1.9.
I get it to pass and display data from a query in a view just fine as long as its a simple in form_input(). An issue arises when I attempt to post data from a form_textarea() wired up to Bootstrap Markdown with an id="bs-markdown"



Here is a partial of the view:



                    <div class="card-body"> 
<?php echo form_open(site_url("admin/edit_user/".$user->id."/"));?>
<div class="form-row">
<div class="form-group col-md-4">
<?php echo lang('edit_user_fname_label', 'first_name', array('class' => 'form-label'));?>
<?php echo form_input($first_name, 'first_name' , array('class' => 'form-control', 'id' => 'first_name'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_lname_label', 'last_name', array('class' => 'form-label'));?>
<?php echo form_input($last_name, 'last_name' , array('class' => 'form-control', 'id' => 'last_name'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_company_label', 'company', array('class' => 'form-label'));?>
<?php echo form_input($company, 'comnpany' , array('class' => 'form-control', 'id' => 'company'));?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<?php echo lang('edit_user_vat_label', 'vat', array('class' => 'form-label'));?>
<?php echo form_input($vat, 'vat' , array('class' => 'form-control', 'id' => 'vat'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_email_label', 'email', array('class' => 'form-label'));?>
<?php echo form_input($email, 'email' , array('class' => 'form-control', 'id' => 'email'));?>
</div>
<div class="form-group col-md-4">
<?php echo lang('edit_user_phone_label', 'phone', array('class' => 'form-label'));?>
<?php echo form_input($phone, 'phone' , array('class' => 'form-control', 'id' => 'phone'));?>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12"">
<label class="form-label">Status</label>
<select class="custom-select">
<option selected="">Active</option>
<option>Suspended</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-8 col-lg-12 col-xl-6">
<h6 class="card-header">Notes on Customer</h6>
<div class="card-body py-0 px-0">
<?php echo form_textarea('notes',$notes, array('id' => 'bs-markdown'));?>
</div>
</div>
</div>
</div>
<?php echo form_hidden('id', $user->id);?>
<?php echo form_hidden($csrf); ?>
<div class="text-right mt-3">
<input type="submit" name="submit" value="Update" class="btn btn-primary">
</div>

<?php echo form_close();?>
</div>
<!-- / Content -->

<script>
// Bootstrap Markdown
$(function() {
$('#bs-markdown').markdown({
iconlibrary: 'fa',
footer: '<div id="md-character-footer"></div><small id="md-character-counter" class="text-muted">600 character left</small>',

onChange: function(e) {
var contentLength = e.getContent().length;

if (contentLength > 600) {
$('#md-character-counter')
.removeClass('text-muted')
.addClass('text-danger')
.html((contentLength - 600) + ' character surplus.');
} else {
$('#md-character-counter')
.removeClass('text-danger')
.addClass('text-muted')
.html((600 - contentLength) + ' character left.');
}
},
});

// Update character counter
$('#markdown').trigger('change');


// *******************************************************************
// Fix icons

$('.md-editor .fa-header').removeClass('fa fa-header').addClass('fas fa-heading');
$('.md-editor .fa-picture-o').removeClass('fa fa-picture-o').addClass('far fa-image');
});
</script>


Here is the controller:



/**
* Edit a user
*
* @param int|string $id
*/
public function edit_user($id)
{
// Retrieves the operating Users data as Object wich is passed to _navbar
$this->data['operator'] = $this->ion_auth->user()->row();

$user = $this->ion_auth->user($id)->row();

// validate form input
$this->form_validation->set_rules('first_name', $this->lang->line('edit_user_validation_fname_label'), 'trim|required');
$this->form_validation->set_rules('last_name', $this->lang->line('edit_user_validation_lname_label'), 'trim|required');
$this->form_validation->set_rules('phone', $this->lang->line('edit_user_validation_phone_label'), 'trim|required');
$this->form_validation->set_rules('email', $this->lang->line('edit_user_validation_email_label'), 'trim|required');

if (isset($_POST) && !empty($_POST))
{

// do we have a valid request?
if ($this->_valid_csrf_nonce() === FALSE || $id != $this->input->post('id'))
{
show_error($this->lang->line('error_csrf'));
}

if ($this->form_validation->run() === TRUE)
{


//echo var_dump($_POST);
//exit();

$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'company' => $this->input->post('company'),
'phone' => $this->input->post('phone'),
'email' => $this->input->post('email'),
'notes' => $this->input->post('bs'),


);


// check to see if we are updating the user
if ($this->ion_auth->update($user->id, $data))
{
// redirect them back to the admin page if admin, or to the base url if non admin
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('admin/edit_user/'.$id, 'refresh');

}
else
{
// redirect them back to the admin page if admin, or to the base url if non admin
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('admin/edit_user/'.$id, 'refresh');

}

}
}

// set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));

// pass the user to the view
$this->data['user'] = $user;

$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'value' => $this->form_validation->set_value('first_name', $user->first_name),

);
$this->data['last_name'] = array(
'name' => 'last_name',
'id' => 'last_name',
'type' => 'text',
'value' => $this->form_validation->set_value('last_name', $user->last_name),
);
$this->data['company'] = array(
'name' => 'company',
'id' => 'company',
'type' => 'text',
'value' => $this->form_validation->set_value('company', $user->company),
);
$this->data['vat'] = array(
'name' => 'vat',
'id' => 'vat',
'type' => 'text',
'value' => $this->form_validation->set_value('vat', $user->vat),
);
$this->data['email'] = array(
'name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email', $user->email),
);
$this->data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'type' => 'text',
'value' => $this->form_validation->set_value('phone', $user->phone),
);

$this->data['notes'] = $user->notes;

// display the edit user form
$this->data['csrf'] = $this->_get_csrf_nonce();


// VIEW: PARTIALS & TEMPLATE
$partials['_dev_bar'] = $this->load->view('_dev_bar', NULL, TRUE);
$partials['navbar'] = $this->load->view('admin/modules/_navbar', $this->data, TRUE);
$partials['sidenav'] = $this->load->view('admin/modules/_sidenav', NULL, TRUE);
$partials['content'] = $this->load->view('admin/modules/_body-user-customer-edit', NULL, TRUE);
$partials['bottomnav'] = $this->load->view('admin/modules/_bottomnav', NULL, TRUE);
$this->load->view('admin/_admin-template', $partials);
}


/**
* @return array A CSRF key-value pair
*/
public function _get_csrf_nonce()
{
$this->load->helper('string');
$key = random_string('alnum', 8);
$value = random_string('alnum', 20);
$this->session->set_flashdata('csrfkey', $key);
$this->session->set_flashdata('csrfvalue', $value);

return array($key => $value);
}

/**
* @return bool Whether the posted CSRF token matches
*/
public function _valid_csrf_nonce(){
$csrfkey = $this->input->post($this->session->flashdata('csrfkey'));
if ($csrfkey && $csrfkey === $this->session->flashdata('csrfvalue')){
return TRUE;
}
return FALSE;
}

public function redirectUser(){
if ($this->ion_auth->is_admin()){
redirect('admin', 'refresh');
}
redirect('/', 'refresh');
}


A var_dump($Post) reveals that notes is not even posted to the array:



array(9) { 
["first_name"]=> string(7) "Johnwww"
["last_name"]=> string(5) "Ddddd"
["company"]=> string(0) ""
["vat"]=> string(0) ""
["email"]=> string(12) "john@doe.com"
["phone"]=> string(8) "07009090"
["id"]=> string(1) "3"
["91EnDeLb"]=> string(20) "0ibAqJsuo9mkVzKlRrEy"
["submit"]=> string(6) "Update"
}


If I omit referencing bootsrap markdown as an id="bs-markdown" in the textarea of the view them the var_dump() includes the item ["notes"]=> string(5) "notes"



Any pointer on how to proceed would be appreciated.







codeigniter bootstrap-4 http-post textarea markdown






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 18:42









MarcusMarcus

31




31













  • fyi codeigniter has it's own CSRF system that is pretty good. anyways if this plugin is anything like CKeditor or the like, the contents aren't posted by default and can be gotten via some function. This usually makes it easy for ajax, but a pain for regulator posting. I'm not sure how you would do it in this plugin. However as doesn't seem to be actively maintained I would switch to something like CK, tinymce, or my favorite - summernote

    – Alex
    Nov 17 '18 at 2:36











  • I did end up using summernote, with success. Thank you.

    – Marcus
    Nov 17 '18 at 13:07



















  • fyi codeigniter has it's own CSRF system that is pretty good. anyways if this plugin is anything like CKeditor or the like, the contents aren't posted by default and can be gotten via some function. This usually makes it easy for ajax, but a pain for regulator posting. I'm not sure how you would do it in this plugin. However as doesn't seem to be actively maintained I would switch to something like CK, tinymce, or my favorite - summernote

    – Alex
    Nov 17 '18 at 2:36











  • I did end up using summernote, with success. Thank you.

    – Marcus
    Nov 17 '18 at 13:07

















fyi codeigniter has it's own CSRF system that is pretty good. anyways if this plugin is anything like CKeditor or the like, the contents aren't posted by default and can be gotten via some function. This usually makes it easy for ajax, but a pain for regulator posting. I'm not sure how you would do it in this plugin. However as doesn't seem to be actively maintained I would switch to something like CK, tinymce, or my favorite - summernote

– Alex
Nov 17 '18 at 2:36





fyi codeigniter has it's own CSRF system that is pretty good. anyways if this plugin is anything like CKeditor or the like, the contents aren't posted by default and can be gotten via some function. This usually makes it easy for ajax, but a pain for regulator posting. I'm not sure how you would do it in this plugin. However as doesn't seem to be actively maintained I would switch to something like CK, tinymce, or my favorite - summernote

– Alex
Nov 17 '18 at 2:36













I did end up using summernote, with success. Thank you.

– Marcus
Nov 17 '18 at 13:07





I did end up using summernote, with success. Thank you.

– Marcus
Nov 17 '18 at 13:07












1 Answer
1






active

oldest

votes


















0














The best solution I could come up with (and you may find better) is to do this:



$('form').on('submit', function(e){
var textarea = $('#bs-markdown');
var value = $('#bs-markdown').data('markdown').getContent();
$('#some_hidden_field').attr('value', value);
});


Where some_hidden_field is a blank hidden field.



Applying it the bs-markdown value yielded nothing in post.



But again, I would suggest using a different, more actively maintained editor.






share|improve this answer
























  • I ended up using a different, more maintained editor; summernote. And it posts properly. Thanks for the tip! <3

    – Marcus
    Nov 17 '18 at 13:07











  • yea it's a good one. happy coding ;)

    – Alex
    Nov 17 '18 at 22:07














Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343647%2fcodeigniter-bootstrap-markdown-textarea%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The best solution I could come up with (and you may find better) is to do this:



$('form').on('submit', function(e){
var textarea = $('#bs-markdown');
var value = $('#bs-markdown').data('markdown').getContent();
$('#some_hidden_field').attr('value', value);
});


Where some_hidden_field is a blank hidden field.



Applying it the bs-markdown value yielded nothing in post.



But again, I would suggest using a different, more actively maintained editor.






share|improve this answer
























  • I ended up using a different, more maintained editor; summernote. And it posts properly. Thanks for the tip! <3

    – Marcus
    Nov 17 '18 at 13:07











  • yea it's a good one. happy coding ;)

    – Alex
    Nov 17 '18 at 22:07


















0














The best solution I could come up with (and you may find better) is to do this:



$('form').on('submit', function(e){
var textarea = $('#bs-markdown');
var value = $('#bs-markdown').data('markdown').getContent();
$('#some_hidden_field').attr('value', value);
});


Where some_hidden_field is a blank hidden field.



Applying it the bs-markdown value yielded nothing in post.



But again, I would suggest using a different, more actively maintained editor.






share|improve this answer
























  • I ended up using a different, more maintained editor; summernote. And it posts properly. Thanks for the tip! <3

    – Marcus
    Nov 17 '18 at 13:07











  • yea it's a good one. happy coding ;)

    – Alex
    Nov 17 '18 at 22:07
















0












0








0







The best solution I could come up with (and you may find better) is to do this:



$('form').on('submit', function(e){
var textarea = $('#bs-markdown');
var value = $('#bs-markdown').data('markdown').getContent();
$('#some_hidden_field').attr('value', value);
});


Where some_hidden_field is a blank hidden field.



Applying it the bs-markdown value yielded nothing in post.



But again, I would suggest using a different, more actively maintained editor.






share|improve this answer













The best solution I could come up with (and you may find better) is to do this:



$('form').on('submit', function(e){
var textarea = $('#bs-markdown');
var value = $('#bs-markdown').data('markdown').getContent();
$('#some_hidden_field').attr('value', value);
});


Where some_hidden_field is a blank hidden field.



Applying it the bs-markdown value yielded nothing in post.



But again, I would suggest using a different, more actively maintained editor.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 17 '18 at 3:15









AlexAlex

6,29042465




6,29042465













  • I ended up using a different, more maintained editor; summernote. And it posts properly. Thanks for the tip! <3

    – Marcus
    Nov 17 '18 at 13:07











  • yea it's a good one. happy coding ;)

    – Alex
    Nov 17 '18 at 22:07





















  • I ended up using a different, more maintained editor; summernote. And it posts properly. Thanks for the tip! <3

    – Marcus
    Nov 17 '18 at 13:07











  • yea it's a good one. happy coding ;)

    – Alex
    Nov 17 '18 at 22:07



















I ended up using a different, more maintained editor; summernote. And it posts properly. Thanks for the tip! <3

– Marcus
Nov 17 '18 at 13:07





I ended up using a different, more maintained editor; summernote. And it posts properly. Thanks for the tip! <3

– Marcus
Nov 17 '18 at 13:07













yea it's a good one. happy coding ;)

– Alex
Nov 17 '18 at 22:07







yea it's a good one. happy coding ;)

– Alex
Nov 17 '18 at 22:07






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343647%2fcodeigniter-bootstrap-markdown-textarea%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python