CodeIgniter Forums
Problem with passing values to bootstrap modal window - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Problem with passing values to bootstrap modal window (/showthread.php?tid=72746)

Pages: 1 2


Problem with passing values to bootstrap modal window - shamiul72 - 02-06-2019

I am just start creating a database update system with a bootstrap modal window. I am using ajax to populate the modal form fields but not getting any value. Please review the code and help me to figure out the error.

 HTML Code
Code:
<!-- Modal -->
        <div class="modal fade" id="edit_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">Edit Data</h4>
                  </div>
                  <div class="modal-body">
                      <div class="content-wrapper content-wrapper--with-bg">
                      <?php echo form_open('quotation'); ?>
                           <p>
                            <input type="text" name="bname" id="bname" required class="form-control custom-ctrl" placeholder="Billing Name">
                           </p>  
                           <span class="text-danger"><?php echo form_error('bname'); ?></span>
                           <p>
                            <input type="text" name="company" id="company" required class="form-control custom-ctrl" placeholder="Company">
                           </p>
                           <span class="text-danger"><?php echo form_error('company'); ?></span>
                            <input type="hidden" name="id" id="id"> 
                            </p>
                            <button type="submit" id="update" class="btn btn-primary btn-custom pull-right"> Update</button>
                            <br>
                        <?php echo form_close(); ?>
              </div>
            </div>
          </div>
        </div>
      </div>

My Controller

PHP Code:
public function fetch_by_id(){
    $this->load->model("quotation_model");
    $result $this->quotation_model->fetch_by_id();
    echo json_encode($result);   


And Here is the Modal associated with the controller.


PHP Code:
public function fetch_by_id(){
    $id $this->input->get('id');
    $this->db->where('id'$id);
    $query $this->db->get('quotes');
    return $query->result();


Here is the ajax code
Code:
$(document).on('click', '.editBtn', function(){
   var id = $(this).attr('data');
   $('#edit_modal').modal('show');

   $.ajax({
       type: 'ajax',
       method: 'get',
       url: '<?php echo base_url(); ?>quotation/fetch_by_id',
       data: {id: id},
       async: false,
       dataType: 'json',
       success: function(data){
          $("input[name=id]").val(data.id);
          $("input[name=bname]").val(data.bname);
          $("input[name=company]").val(data.company);
       },
       error: function(){
           alert('Could not displaying data');
       },
   });
});

I am just able to popup the modal window but not getting any value


RE: Problem with passing values to bootstrap modal window - chronic - 02-06-2019

Try to see if this tutorial can help you:

https://www.codexworld.com/codeigniter-crud-operations-without-page-refresh-jquery-ajax/


RE: Problem with passing values to bootstrap modal window - InsiteFX - 02-06-2019

I do not recommend having two functions/methods with the same name, your just asking for trouble.
Rename one of them to a different name.


RE: Problem with passing values to bootstrap modal window - shamiul72 - 02-06-2019

(02-06-2019, 09:24 AM)InsiteFX Wrote: I do not recommend having two functions/methods with the same name, your just asking for trouble.
Rename one of them to a different name.
But this is not the problem in my case...right?


RE: Problem with passing values to bootstrap modal window - skunkbad - 02-06-2019

The action of your form clearly points to a method named quotation, but the name of the method in your controller is fetch_by_id. So unless you have some magic routing that we're not aware of, that's your problem.


RE: Problem with passing values to bootstrap modal window - shamiul72 - 02-06-2019

(02-06-2019, 10:47 AM)skunkbad Wrote: The action of your form clearly points to a method named quotation, but the name of the method in your controller is fetch_by_id. So unless you have some magic routing that we're not aware of, that's your problem.
@skunkbad please check again, i have forgot to include the ajax


RE: Problem with passing values to bootstrap modal window - skunkbad - 02-06-2019

(02-06-2019, 11:45 AM)shamiul72 Wrote:
(02-06-2019, 10:47 AM)skunkbad Wrote: The action of your form clearly points to a method named quotation, but the name of the method in your controller is fetch_by_id. So unless you have some magic routing that we're not aware of, that's your problem.
@skunkbad please check again, i have forgot to include the ajax

You must specify a content-type header for JSON:


PHP Code:
header('Content-Type: application/json'); 



RE: Problem with passing values to bootstrap modal window - shamiul72 - 02-06-2019

(02-06-2019, 01:12 PM)skunkbad Wrote:
(02-06-2019, 11:45 AM)shamiul72 Wrote:
(02-06-2019, 10:47 AM)skunkbad Wrote: The action of your form clearly points to a method named quotation, but the name of the method in your controller is fetch_by_id. So unless you have some magic routing that we're not aware of, that's your problem.
@skunkbad please check again, i have forgot to include the ajax

You must specify a content-type header for JSON:


PHP Code:
header('Content-Type: application/json'); 
No Luck still facing the empty fields  Sad


RE: Problem with passing values to bootstrap modal window - InsiteFX - 02-07-2019

Here is an example on how to do it in CodeIgniter with Ajax.

View data in a Bootstrap modal using Ajax, jQuery and PHP


RE: Problem with passing values to bootstrap modal window - InsiteFX - 02-07-2019

Here is an example.

jQuery AJAX Example