Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter - using set_value() to populate a form for editing (with no POST involved)

I have a view containing a form. with input fields and radio buttons. This form needs to be populated with the data from database, so as to use it as an data editing form.

I have used the set_value() function for the form validation where the view is called from the same controller after the post. But how to use set_value function with out a POST? i.e. simply populate the values in a form in the view that's loaded. with say, an Array or object from database.

like image 541
Archer Avatar asked Jun 27 '13 06:06

Archer


People also ask

What is Set_value in CodeIgniter?

The set_value function just sets the value, the only benefit to using it is it simplifies setting the value to an already submitted value when redisplaying the form or showing a default value when the form has yet to be submitted.

How to use CodeIgniter form validation?

Create a view file myform. php and save the below code it in application/views/myform. php. This page will display form where user can submit his name and we will validate this page to ensure that it should not be empty while submitting.

How to set validation rules in CodeIgniter?

CodeIgniter lets you set as many validation rules as you need for a given field, cascading them in order, and it even lets you prep and pre-process the field data at the same time. To set validation rules you will use the set_rules() method: $this->form_validation->set_rules();


1 Answers

You can use it like this

set_value('myfield', isset($databaseData['myfield']) ? $databaseData['myfield'] : '');

$databaseData will contain the data from the database which you have loaded in the controller and passed to view

$data['databaseData']= $this->my_model->find($parameters);

$this->load->view('myformview',$data);
like image 200
M Khalid Junaid Avatar answered Sep 20 '22 08:09

M Khalid Junaid