2016-04-13 18 views
1

dbにデータを作成/挿入する際に問題が発生しています。フォームを送信すると、form_validationを使用してエラーが返されます。私の以前のデータベースで動作しますが、現在は動作しません。私はそれがデータ型列挙型であるとは思わない。codeigniter enumフィールドを使用してデータベースにデータを挿入

コントローラ:

public function create_item() { 
    $data = array(
    'checklist_id' => $this->input->post('checklist_id'), 
    'title' => $this->input->post('title'), 
    'description' => $this->input->post('description'), 
    'type' => $this->input->post('type'), //with enum type 
    'section' => $this->input->post('section'), 
    'order_no' => $this->input->post('order_no'), 
    'status' => $this->input->post('status'), //with enum type 
    'date_created' => $this->input->post('date_created') 
    ); 

    $this->form_validation->set_rules('title','Item Title','trim|required|callback_alpha_dash_space'); 
    $this->form_validation->set_rules('order_no','Item Order','trim|required'); 

    $this->form_validation->set_message('alpha_dash_space', '%s appears to be invalid. Must contain only alphabets.'); 
    $this->form_validation->set_message('required', '%s field must not be empty. '); 

    if ($this->form_validation->run() == FALSE) { 
    $this->session->set_flashdata('error', ' Error adding an item!'); 
    redirect($this->agent->referrer()); 
    } else { 
     $result = $this->checklist_item_model->put_item($data); 
     if (!$result == TRUE) { 
     $this->session->set_flashdata('success', 'Item added successfuly!'); 
     redirect('checklist_item', 'refresh'); 
     } 
    } 
} 

ビュー:

<select class="form-control" id="status" name="status"> 
    <option value="0">Incomplete</option> 
    <option value="1">Complete</option> 
</select> 
+0

あなたの検証コード –

+0

をさらに詳しく説明できます。また、 –

+0

というエラーが発生した場合は、速やかに対応してください。上記の私の編集を見てください。 – claudios

答えて

0

簡単にあなたがエラーフィールドをトレースすることができ、あなたのコントローラ

$this->form_validation->set_rules('title','ItemTitle','trim|required|callback_alpha_dash_space'); 
$this->form_validation->set_rules('order_no','Item Order','trim|required'); 

$this->form_validation->set_message('alpha_dash_space', '%s appears to be invalid. Must contain only alphabets.'); 
$this->form_validation->set_message('required', '%s field must not be empty. '); 
     if ($this->form_validation->run() == TRUE) { 
      // do something here 
      $this->session->set_flashdata('success', 'Item added successfuly!'); 
    redirect('checklist_item', 'refresh'); 
     } 

とビューショーの検証エラーでは、このような検証を行います

<?php if(validation_errors()) { ?> 
    <div class="alert alert-danger"><?php echo validation_errors(); ?></div> 
    <p class="text-center mb30"></p> 
    <?php } ?> 
+0

このコードを試してみます。 – claudios

+0

の直後に戻りますが、falseも返されます。 – claudios

関連する問題