![]() |
How to re-populate the form with values from the database? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to re-populate the form with values from the database? (/showthread.php?tid=32463) |
How to re-populate the form with values from the database? - El Forum - 07-24-2010 [eluser]Yanny[/eluser] Hi all, I know how to re-populate the form with post data, via set_value('fieldname'); Now I want to re-populate the form with post data again but the post data contains data from the database. How to do that? Normally without using framework I will do something like this: Code: //when there are not post values do this So how to do this now with CodeIgniter? I have tried something like this: Code: $this->input->post('username') = $data['user']['username']; I know you guys know how to do it, since this is a common thing. Thanks in advance! How to re-populate the form with values from the database? - El Forum - 07-24-2010 [eluser]Higher Ground Studio[/eluser] I would use ajax to submit the form and return json or xml O(from your server side validation script) to a js function that then adds it to the form values. Pretty easy to do. How to re-populate the form with values from the database? - El Forum - 07-24-2010 [eluser]Yanny[/eluser] Is there a way without using ajax? How to re-populate the form with values from the database? - El Forum - 07-24-2010 [eluser]cahva[/eluser] set_value() will take second parameter which you can use to populate the fields if data has not yet been sent. With that you can set the default value if the value is not posted yet. Something like this.. Controller: Code: function index() View: Code: <?php echo form_open('user') ?> How to re-populate the form with values from the database? - El Forum - 07-24-2010 [eluser]Yanny[/eluser] Thank you so much cahva! That's what I need! Maybe I better read the user guide before asking... haha.. How to re-populate the form with values from the database? - El Forum - 03-05-2011 [eluser]BandonRandon[/eluser] This a great, but how may you suggest doing the same thing with Checkboxs and Radios? I am storing the correct vaule as a number in my database. How to re-populate the form with values from the database? - El Forum - 03-24-2012 [eluser]Unknown[/eluser] I suggest the following method for filling the form fields with database values. Code: if(!empty($_POST)){ in this way, the form is filled with the DB data, or when the user changed the data, submitted, but a error occured, the form is filled again but now with the data from the POST. |