form_validation スケルトン
フォーム関連でよく使うControllerスケルトン。
<?php function add() { //フォームチェック $this->form_validation->set_rules($this->add_form); //入力チェック if (!$this->form_validation->run() or $this->input->post('back')) { //入力フォーム表示 初回とエラーはこっち $data['confirm'] = true; $data['back'] = false; $data['submit'] = false; $this->view('', $data); } else { //確認と登録 if(!$this->input->post('submit')){ //確認 $data['confirm'] = false; $data['back'] = true; $data['submit'] = true; $data['post'] = $this->input->post(); $this->view('' $data, true); } else { //登録 $post_array = $this->input->post(); $this->user_profiles->set_array_data($post_array); $this->user_profiles->insert(); redirect('match/admin/add_done/'); } } }
上記が大まかな処理。
Form Validationのルールは下記で定義する。
<?php private $add_form = array( array( 'field' => 'r_id', 'label' => 'ユーザーID', 'rules' => 'required' ), array( 'field' => 'r_password', 'label' => 'パスワード', 'rules' => 'required' ), );
登録処理が走った後は、リダイレクトでこちらに飛ぶ。
これで、2重登録をある程度防げるはず。
<?php function add_done() { $this->view('', $data); }