This is the code i have so far ..
View :
<script>
<?php if($state == 'add') { ?>
$(document).ready(function() {
$('#beneficiar_p_display_as_box').append('<a class="btn" id="button" data-toggle="modal" data-target=".bs-example-modal-lg"><i class="icon-plus-sign"></i> Add </a>');
});
<?php } ?>
</script>
<div class="modal fade bs-example-modal-lg" tabindex="-1" id="myModal" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
<h4 id="myLargeModalLabel" class="modal-title">Add</h4>
</div>
<div class="modal-body" >
<form class="sky-form" id="sky-inchidere" method="post" accept-charset="utf-8" action="">
<dl class="dl-horizontal" style="min-height:100px">
<dt>Name<span class="color-red">*</span></dt>
<dd>
<section>
<label class="input">
<i class="icon-append fa fa-inbox"></i>
<input type="text" value="" name="name" id="name" required>
<b class="tooltip tooltip-bottom-right">Add</b>
</label>
</section>
</dd>
</dl>
<button type="submit" class="btn-u" style="float:right; margin-top:-35px;">Submit</button>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#sky-inchidere").submit(function(e) {
e.preventDefault();
var tdata= $("#sky-inchidere").serializeArray();
$.ajax({
type: "POST",
url: 'http://localhost/new/test/add',
data: tdata,
success:function(tdata) {
// close the model
$('#myModal').modal('hide');
// update dropdownlist ??
$('.field-beneficiar_p').trigger('chosen:updated');
},
error: function (XHR, status, response) {
alert('fail');
}
});
});
});
</script>
Controller (I added the modal code here for test) :
public function add() {
$tdata = array( 'name' => $this->input->post('name') );
$this->db->insert('table', $tdata);
}
All works good except I don't no how to update the dropdownlist with the new item added .... If someone done this any help will be appreciated.
.