HR Web Solution HR Web Solution - 7 months ago 8
PHP Question

How to set value with set value function in codeignter

<input type="hidden" name="template" value="<?php echo set_value ('template',$temp); ?>" />


public function index($id=NULL)
{
if(empty($id)){
redirect('service');
}else{
$this->load->model('servicemodel');
$pro = $this->servicemodel->get_pro_info($id);
if($pro){
$this->load->helper('form');
$data['temp']=$pro['0']['name'];
$data['page']="buynow/userform";
$this->load->view('buynow/paymentindia',$data); }


public function user_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters("<p class='text-danger'>","</p>");
if ($this->form_validation->run('uservalidation')){

// validation success
}else{

$this->load->helper('form');
$this->load->view('buynow/paymentindia',$data);
}
}


I want to fill data in set value, an error comes on undefined
$temp


My form is in different function but validation is in different function, when we any error occur in validation
$temp
showing undefined variable.

Any help will greatly appreciated..
Thank you

Answer

suppose here is your controller

public function registerForm(){
  //you have to pass a value to $temp
  $data[temp] = '101';
  $this->load->view('register',$data);
}

now you will get the value on your register.php view file

you are not passing any value to $temp after validation fail

use following code

public function user_validation()
{
  $this->load->library('form_validation');
  $this->form_validation->set_error_delimiters("<p class='text-danger'>","</p>");
   if ($this->form_validation->run('uservalidation')){
     // validation success
   }else{
      // you have to pass value again to $temp
      $data['temp'] = $this->input->post('template');
      $this->load->helper('form');
      $this->load->view('buynow/paymentindia',$data);
   }
 }