2016-10-08 3 views
0

ページがリフレッシュされると、データはNULL値でデータベースに追加されます。送信ボタンがクリックされたときにのみそれらを渡したいと思います。それを実行する方法?次のようにビューの[送信]ボタンをクリックした場合にのみ、コントローラにデータを渡す方法は?

ビュー

私のコードは次のとおりです。

<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); 
+0

フォーム検証に関するCodeigniterユーザーガイドを読んでください。 https://www.codeigniter.com/userguide3/libraries/form_validation.html#form-validation-tutorial – TimBrownlaw

+0

コントローラメソッドを使用してページをURLとして開き、フォームの別のコントローラメソッドを使用することをお勧めします。私は二人とも一緒に見たことがないし、私は彼らがすべきだとも思わない – Brad

答えて

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 
    } 
} 
関連する問題