CodeIgniter Forums
Passing data from View to Model (where --> from view input) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Passing data from View to Model (where --> from view input) (/showthread.php?tid=59585)



Passing data from View to Model (where --> from view input) - El Forum - 10-23-2013

[eluser]hrg.vincent[/eluser]
//View
Code:
<input type="input" id="tcs_fname" name="tcs_fname" />
<input type="input" id="tcs_passport" name="tcs_passport" />

//Controller
Code:
public function getVisaStatus()
{
$this->load->helper('form');  
$data = array(
  'family_name'  => $this->input->post("tcs_fname"),
  'passport_no'  => $this->input->post("tcs_passport")
);
$this->load->model('Data_m');
        $data['visa_status'] = $this->Data_m->getVisaStatus($data);
        $this->load->view('ajax/home', $data);
}

//Model
Code:
function getVisaStatus($data)
{  
$this->db->select('(CASE WHEN (AP.status = "AP") THEN "Approved" WHEN (AP.status = "RJ") THEN "Rejected" ELSE "Pending" END) as visa_status, VE.embassy_name');  
$this->db->from(VISA_APPLICATION. ' as AP');
$this->db->join(EMBASSY_TABLE. ' as VE', 'VE.embassy_id = AP.embassy', 'left');
$this->db->where('AP.status !=', 'CC');
$this->db->like('passport_no', $data["passport_no"]);
$this->db->like('family_name', $data["family_name"]);
  
$result = $this->db->get();
$return = array();
if($result->num_rows() > 0) {
  return $result->result_array();
}
}

Anyone can help on how to pass data from View to Model as I need to get the where condition, data is from view input text.


Passing data from View to Model (where --> from view input) - El Forum - 10-24-2013

[eluser]Tpojka[/eluser]
Shouldn't it be:
Code:
<input type="text">
?
Input types.


Passing data from View to Model (where --> from view input) - El Forum - 10-24-2013

[eluser]Ckirk[/eluser]
Can you give us more info? You're not being clear in what you are trying to achieve.
Any data in the view was put there by the application so it's already available to your model.

and yes... input type="text" Smile








Passing data from View to Model (where --> from view input) - El Forum - 10-24-2013

[eluser]hrg.vincent[/eluser]
I think is javascript problem because I used i to control.

Code:
function loadHomeFn(){
$.ajax({
  type: "GET",
  url: '<?php echo site_url('ajax/getVisaStatus'); ?>/ ',

  success: function(r){
   handleErrorFn(r);
      
   $("#rp-holder").html(r);
   $('#c_status a').click(function(e){
    $.post("<?php echo site_url('ajax/getParameter'); ?>/",
     function (r){
      loadHomeFn();
     }
    );
   });
  }
});
}

May I know how to passing data from javascript to controller?


Passing data from View to Model (where --> from view input) - El Forum - 10-25-2013

[eluser]Ckirk[/eluser]
To pass data to the controller you will use the GET or POST. same as you did with your loadHomeFn.
Your controller will need to be able to handle the information being sent to it, of course.







Passing data from View to Model (where --> from view input) - El Forum - 10-25-2013

[eluser]hrg.vincent[/eluser]
I've change some of my code in controller, but still can't get the data from javascript.

Code:
public function getVisaStatus()
{
$this->load->helper('url');
$this->load->helper('form');

// Here is the code change, and try to get data from javascript
$tcs_fname = $this->input->post("tcs_fname");
$tcs_passport = $this->input->post("tcs_passport");
  
$this->load->model('Data_m');
$data['visa_status'] = $this->Data_m->getVisaStatus($tcs_fname, $tcs_passport);
$this->load->view('ajax/home', $data);
}

Please help...