how to set a default value in codeigniter? how to set a default value in codeigniter? codeigniter codeigniter

how to set a default value in codeigniter?


If your form is posting the data on the same method wherefrom it is rendered then the best approach is that; keep the value in the method itself and use it after form submit.

public function edit() {      $id = 12;     if ($this->form_validation->run()) {         $dataComm    = array(                            'id'  => $id                            'name'       => $this->input->post('name')                             );                            $result_comm = $this->Common_model->insert_data('cw_franchise_commission', $dataComm);     }     $this->data['title'] = "Edit User";     $this->load->view('edit', $this->data); }

And if your form action is another method then you can encode the value and decode it after form submission.

To Encode

bin2hex(base64_encode($id))

To Decode

base64_decode(hex2bin($this->input->post('id')));

One more thing if you are using hidden inputs then you should name it something confusing not clear at all. Otherwise, anyone can understand the purpose of the field.


There is no such a way but you can keep it in encoding format using

base64_encode()

<input type="hidden" name="id" value="<php echo base64_encode('1231231231'.$id); ?>">

"1231231231" just for additional security which will preprend with the id

cut "1231231231" in controller like below to get the id

    function abc() {    if (isset($_POST['id']) && !empty($_POST['id'])) {        $id = substr(base64_decode($_GET['id']), 10); // to remive extra string        if (!empty($id)) {            // you  get id here        } else {            //if someone attempt to tamper with the id then it will retrive blank        }    } else {        //redirect or show error    }}