![]() |
Form helper Set_value function - 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: Form helper Set_value function (/showthread.php?tid=53600) |
Form helper Set_value function - El Forum - 07-31-2012 [eluser]minerbog[/eluser] Hi Guys, Now I'm not sure if im barking up the wrong tree here, but I am trying to do a little as possible (as normal ![]() I have a view file I want to use for inputing and editing data. Code: <?php echo validation_errors(); ?> This works fine for adding and validating new records. However, I assumed that because the set_value function uses the $_POST variable I could do this: Code: public function edit($id) The $_POST array displays ok on the view page with print_r but set_value doesn't seem to use it and returns blank fields. Have I done something obviously wrong or just an idiot for trying something it cannot do!! Regards, Gav. Form helper Set_value function - El Forum - 07-31-2012 [eluser]Aken[/eluser] It's generally best practice to not deal directly with the $_POST array in CI apps. If you want to include default values in a form, use the second parameter of set_value(). Form helper Set_value function - El Forum - 08-01-2012 [eluser]minerbog[/eluser] Thanks Aken I do fully understand that but I think the point is being missed. For 'default' values, yes set value is the best option. But the values are being returned from a db and I am trying to use the same view for both returned values and default values. Form helper Set_value function - El Forum - 08-01-2012 [eluser]Aken[/eluser] You're trying to get values from your database to be in your form upon first loading it. To do that, you need to use the second parameter of set_value(). Form helper Set_value function - El Forum - 08-01-2012 [eluser]minerbog[/eluser] I've been an idiot!! Thinking aloud so bare with me :| So if I get a database return to say the $db var. Then using: Code: <?php echo set_value('address1',@$db['address1']); ?> Thanks Aken, sometimes we all need nudge!! PS. Like you website by the way! Form helper Set_value function - El Forum - 08-01-2012 [eluser]Aken[/eluser] There ya go :-p I wouldn't use the error suppression, I would add code to verify that the particular items exist (even if it means creating default blank ones) before passing the array to the view. Error suppression is cheap and not a great coding style. And thank you ![]() |