2017-09-19 8 views
0

contollerからタグのビューセクションに配列を渡そうとしています。 データベースに値を挿入するためのフォームの検証とモデルが存在しないときは以前は動作していました。フォームの検証がコントローラから削除された場合、フォームはエラーを示すnull値で直接送信されます。column_nameはnullにはなりません。私のコードで何が間違っていますか?私を助けてください! IAMデータベースコントローラーの配列を<select>タグの表示セクションに渡そうとしています - オプションが表示されない - 機能していません。

public function insert_skill() { 
    $data = array(
     'give_my_best' => $this->input->post('give_my_best'), 
     'occupation' => $this->input->post('skills'), 
     'have_done' => $this->input->post('have_done'), 
     'work' => $this->input->post('work') 
    ); 
    $this->db->insert('profiles',$data); 
} 

ビューに値を挿入する

public function getskill() 
{ 
    if (!$this->session->userdata('logged_in')) { 
     redirect('login'); 
    } 

    $this->form_validation->set_rules('give_my_best', 'Give my best', 'required'); 
    $this->form_validation->set_rules('skills', 'Skills', 'required'); 
    $this->form_validation->set_rules('have_done', 'Have done', 'required'); 
    $this->form_validation->set_rules('work', 'I work', 'required'); 

    if ($this->form_validation->run() === false) { 
     $this->load->view('templates/pheader'); 
     $this->load->view('profile/editskill'); 
     $this->load->view('templates/pfooter'); 
    } else { 
     $dataArr = array(

      "give_my_best" => ["On Stage", "Back Stage", "Services"], 
      "OnStage"  => ["Actor", "Modelling", "Theatre Artist", "Dancer", "Singer", "Comedian", "Stand-up", "Voice-over", "Musician", "Composer", "Stunts", "Junior Artist", "Child Artist", "Compere/Host", "Reality show artist"], 
      "BackStage" => ["Producer", "Financer", "Director", "Story Writer", "Lyricist", "Dialogue writer", "Action", "Screenplay", "Cinematography", "Art Director", "Background score", "Editing", "Choreography", "Sound design", "Special Effects", "Costume design", "Make up artist", "Content writer"], 
      "Services"  => ["Prop suppplier", "Technician", "Vendor"] 


     ); 
     $this->load->view('templates/pheader'); 
     $this->load->view('profile/editskill', $dataArr); 
     $this->load->view('templates/pfooter'); 

     $this->profile_model->insert_skill(); 
     redirect('profile/vabout'); 
    } 
} 

モデル私の見解に配列を渡す

コントローラ:これはIAM配列を渡す形である

<form method="post" id="editskill" action="<?php echo base_url(); ?>profile/getskill" name="editskill"> 
    <div class="form-group"> 
     <label class="col-md-3 text-right">I give my best:</label> 
     <div class="col-md-9"> 
      <select class="chosen-select" 
        name="give_my_best" 
        data-placeholder="Give best" 
        tabindex="6" 
        id="" 
        multiple="multiple"> 
       <?php foreach($give_my_best as $value) { ?> 
       <option value="<?php echo $value; ?>"><?php echo $value; ?></option> 
       <?php } ?> 
      </select> 
     </div> 
    </div> 
    <br><br><br> 
    <div class="form-group"> 
     <label class="col-md-3 text-right">Skills:</label> 
     <div class="col-md-9"> 
      <select class="chosen-select" name="skills" data-placeholder="Skills" tabindex="6" id="" 
        multiple="multiple"> 
       <optgroup label="On Stage"> 
        <?php foreach($OnStage as $value) { ?> 
        <option value="<?php echo $value; ?>"><?php echo $value; ?></option> 
        <?php } ?> 
       </optgroup> 
       <optgroup label="Back Stage"> 
        <?php foreach($BackStage as $value) { ?> 
        <option value="<?php echo $value; ?>"><?php echo $value; ?></option> 
        <?php } ?> 
       </optgroup> 
       <optgroup label="Services"> 
        <?php foreach($Services as $value) { ?> 
        <option value="<?php echo $value; ?>"><?php echo $value; ?></option> 
        <?php } ?> 
       </optgroup> 
      </select> 
     </div> 
    </div> 
    <br><br> 
    </div> <!-- Angular JS ends here --> 
    <div class="form-group"> 
     <button type="submit" 
       class="btn btn-primary col-md-7 col-md-offset-3 text-right" 
       id="submit" 
       value="submit" 
       name="submit">Submit 
     </button> 
    </div> 
</form> 
お使いのコントローラで
+0

ビューを読み込む理由よりも別のページにリダイレクトする場合 –

+0

'have_done'と 'work'の入力/選択はどこですか? – Vladut

答えて

1

、あなたはビューをロードしてからもそう

$this->profile_model->insert_skill(); 
$this->load->view('templates/pheader'); 
$this->load->view('profile/editskill', $dataArr); 
$this->load->view('templates/pfooter'); 

としてこれらの行を並べ替えそして、あなたが内側に2つの異なる機能を使用する必要はありません別の

$this->load->view('templates/pheader'); 
$this->load->view('profile/editskill', $dataArr); 
$this->load->view('templates/pfooter'); 

$this->profile_model->insert_skill(); //put this line before you load the views 
redirect('profile/vabout'); //you can remove this line 

にそれをリダイレクトしますコントローラーがフォームを送信するには、1つの関数で行うことができます。フォームが送信されているかどうかを確認する必要があります。#insert code else通常の表示を表示します。

+0

私はこれを試してみましたが、動作していません... @Harish –

関連する問題