![]() |
set_value and populating a 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: set_value and populating a form with values from the database (/showthread.php?tid=14792) |
set_value and populating a form with values from the database - El Forum - 01-15-2009 [eluser]everdaniel[/eluser] Hi everyone! I've been working on this issue for a few days and I have no clue what I might have doing wrong. I need to re-populate a form with values from the database, so what I'm doing in my controller is: Code: $this->form_validation->set_rules('spo_address1', lang('sponsor_form_address1'), 'trim|required|xss_clean'); That code, is for my controller, and in my view file I have: Code: <?= form_input('spo_address1', set_value('spo_address1', isset($spo_address1) ? $spo_address1 : '')); ?> Result: both input boxes are empty when I load the page (the variables are set and they both have values in it). I checked the set_value function in the Form_validation library, and I saw that the default value is returned only if the field name is not set in the _field_data array (which is built, if I'm correct, when the rules are set), and since I did set them, then the postdata is returned (which I don't have any since I'm loading them from DB). Changing the line 732 in Form_validation.php file from: Code: if ( ! isset($this->_field_data[$field])) Code: if ( ! isset($this->_field_data[$field]['postdata'])) Can someone here point me out in the right direction? Thanks everybody! (Using the latest version of CI from SVN, Revision 1596) set_value and populating a form with values from the database - El Forum - 01-16-2009 [eluser]Future Webs[/eluser] http://ellislab.com/forums/viewthread/97495/ that post may give you a bit of help Im still learning myself though too :-) set_value and populating a form with values from the database - El Forum - 01-16-2009 [eluser]everdaniel[/eluser] [quote author="w3bm" date="1232131856"]http://ellislab.com/forums/viewthread/97495/ that post may give you a bit of help Im still learning myself though too :-)[/quote] hey w3bm! I found out what the problem is a few hours ago, it turns out that the rules are set if there are data in the $_POST var, if there is none which is the most common scenario (since most of the time you click a link to go to an edit page), the rules are not set and the set_value function works (since the fields are not set in the form_validation library). Problem is, I'm not going to the edit page through a link, I'm using a submit button, means the $_POST var is not empty, rules are set, fields are set, set_value doesn't work because it tries to return the postdata value (which is empty). I'm not sure if this is a bug or is an "error of logic" on my end... ![]() |