如果单击“提交”按钮,如何将数据传递给Controller?

时间:2016-10-08 02:20:38

标签: database codeigniter

刷新页面时,数据以空值的形式添加到数据库中。我想仅在单击提交按钮时传递它们。怎么做?

  

查看

我的代码视图如下:

   <form name ="userinput" action="<?php echo base_url(); ?>index.php/patient/periodicalExaminationChart" method="post">

<table width="600" height="200" >

<tr><td>Vitality :</td> <td><select><option>Positive</option><option>Negative </option></select></td></tr>
<tr><td>Recesson :</td> <td><input type="=text" name="form_recesson"></t></td></tr>
<tr><td>Fucation :</td> <td><input type ="text" name="form_fucation"></td><td><img id="toothImage" src="" style="position:absolute; "></td></tr>
<tr><td>Mobility :</td> <td><input type="=text" name="form_mobility"></td></tr>
<tr><td>Pocket Depth:</td> <td><input type ="text" name="form_pocketDepth"></td></tr>
</table>

<button type="submit" class="btn btn-primary"><i class="fa fa-save"></i>Save Details</button>
<button type="reset" class="btn btn-primary"><i class="fa fa-save"></i> Reset Details</button>
</form>
  

控制器

$this->load->helper('url');
        $this->load->view('Header');
        $this->load->view('Patient/periodical_exam');
        $this->load->view('Footer');
        $this->load->model('patient_model');

         $form_data = $this->input->post();
         $data = array(
         'recesson'  => $this->input->post("form_recesson"),
         'fucation'  =>$this->input->post("form_fucation"),
         'mobility'  =>$this->input->post("form_mobility"), 
         'pocketDepth'  => $this->input->post("form_pocketDepth")
         );

         $this->patient_model->save_pExamChart($data);

1 个答案:

答案 0 :(得分:0)

    $this->load->helper('url');
    $this->load->model('patient_model'); // put this in construct method  
 function index()
 {
    if(!$_POST)
    {
      $this->load->view('Header');
      $this->load->view('Patient/periodical_exam');
      $this->load->view('Footer');
    }
    else
    {

     $form_data = $this->input->post();
     $data = array(
     'recesson'  => $this->input->post("form_recesson"),
     'fucation'  =>$this->input->post("form_fucation"),
     'mobility'  =>$this->input->post("form_mobility"), 
     'pocketDepth'  => $this->input->post("form_pocketDepth")
     );

     $this->patient_model->save_pExamChart($data);
     redirect("controller_name"); // your index function 
    }
}