2
votes

I have this issue, I want to fill a form from a variable, what i'm doing right now is passing ID through an anchor on the view, here's the sample

//view search
<?php echo anchor('rfi/addNotification/'.$ID,'Add Notification',array('class'=>'add')); ?>

This calls a function on my controller

function addNotification(){
  $id = $this->input->post('ID');
  $data['results']    =   $this->my_model->addTicket($id);
  $this->load->view('ticketAdd',$data);
}

And the model

function addTicket($id)
{
     if (!empty($id){
        $this->db->like('ID', $id); 
        $query = $this->db->get($this->Table2);
        return $query->result();
     }else {
        echo 'No results to display';
     }
}

But Im not getting any results. I want to prefill some fields, because later I want to save that data on table1

2

2 Answers

0
votes

you are passing the data in anchor like rfi/addNotification/'.$ID...you are not PSOTING it ...so the correct way of getting it is, using functions parameter....

try this

function addNotification($id){
                 //------^^^----here
  $data['results']    =   $this->my_model->addTicket($id);
  $this->load->view('ticketAdd',$data);
}

updated after comment

function addTicket($id)
{
  if (!empty($id){
    $this->db->like('ID', $id); 
    $query = $this->db->get($this->Table2);
    return $query->result_array(); //<---here return as array...
  }else {
    echo 'No results to display';
  }
}
0
votes

If I understand you right, you want to set the value of an input from an variable?

If the input is in the view you access, you can try using the parser class:

Then this is how you will load your view:

$this->load->library('parser');
$this->parser->parse('<your_view>', array(
    'value' => 'your_value'
);

And your view will look like:

<input type="text" name="some_text" value="{value}" />