在form_validation Codeigniter上传递参数

时间:2016-08-02 05:54:24

标签: php forms codeigniter validation parameter-passing

我正在尝试在我的codeigniter项目中使用form_validation创建form_1。 form1中的值将转换为form_2,它也具有form_validation。

这是我的控制器:

 public function daftar() // form_1
  {
    $this->form_validation->set_rules('nama', 'Nama Orang', 'required')
                          ->set_rules('email', 'Email', 'required');
        if ($this->form_validation->run() == FALSE)
        {
        $this->load->view('daftar');
        } else {
        // if success then show form_2
        // and save the value from form_1
        $data = array(
          'nama'    =>$this->input->post('nama'),
          'email'   => $this->input->post('email')
        );
        $this->dftr_own_dis($data);
      }
    }
  }

  public function dftr_own_dis($data_dis) // form_2 contain value from form_1
  {
    $this->form_validation->set_rules('nama_pemilik', 'Nama hehe', 'required');
    if ($this->form_validation->run() == FALSE)
        {
      $data['data_dis'] = $data_dis;
      $this->load->view('daftar_hehe', $data);
    } else {
      echo "succesed all";
    }
  }

问题是form2总是为FALSE,而form_1的值为NULL会使函数daftar_pemilik_dis缺少参数data_dis。

1 个答案:

答案 0 :(得分:0)

请检查表格2验证条件

public function daftar() // form_1
  {
    $this->form_validation->set_rules('nama', 'Nama Orang', 'required')
                          ->set_rules('email', 'Email', 'required');
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('daftar');

        } else {

        // if success then show form_2
        // and save the value from form_1

        $data = array(
          'nama'    =>$this->input->post('nama'),
          'email'   => $this->input->post('email')
        );
        if($this->dftr_own_dis($data)){

            // if validation true then you can add you save code here

            ......... some form or and redirect code or any data save code here .............................


        }else {

            $data['data_dis'] =  $data;

            $this->load->view('daftar_hehe', $data);
        }
      }
    }
  }


public function dftr_own_dis($data_dis) // form_2 contain value from form_1
{

    $this->form_validation->set_rules('name', 'Nama hehe', 'required');

    if ($this->form_validation->run() == FALSE)
    {
      return false;

    } else {

      return true;
    }
}