![]() |
Displaying labels in HTML from $config - 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: Displaying labels in HTML from $config (/showthread.php?tid=12781) |
Displaying labels in HTML from $config - El Forum - 10-30-2008 [eluser]B___[/eluser] Hello: This may have been already covered or may be ridiculously obvious, so I apologize in advance for either case. I am experimenting with the new Form Validation class (which I love so far). Is there an easy way to display the labels that are defined in the $config array when setting rules? I had thought of just passing the $config to the view, but then wouldn't know how to access the label value by specifying the field value. ie: given the following: $config = array( array( 'field' => 'username', 'label' => 'Username', 'rules' => 'required' ), array( 'field' => 'password', 'label' => 'Password', 'rules' => 'required' )); how would one access the label Username by specifying the field username. I didn't see this ability anywhere in the manual, but thought it wouldn't be too hard to write a helper function to do this. Any suggestions? Thanks in advance! Displaying labels in HTML from $config - El Forum - 11-06-2008 [eluser]James Gifford[/eluser] I too would like to be able to output the value for the label as set in the config. I propose something like a set_label helper function similar to the set_value function. This is how I'd like it to work: Controller: Code: $this->form_validation->set_rules(array( View: Code: <?= form_open('login') ?> Or something like that. Displaying labels in HTML from $config - El Forum - 11-06-2008 [eluser]James Gifford[/eluser] I modified the form_helper.php and Form_validation.php files to add the set_label function. Its pretty much the same as the set_value function. form_helper: Code: /** form_validation: Code: /** EDIT: I should mention that I've also modified Form_validation.php by removing the first few lines of the set_rules() method which ignores the rules of there is no post data. Of course, if there's an easier way to get the label value that would be even better. Displaying labels in HTML from $config - El Forum - 11-10-2008 [eluser]B___[/eluser] Awesome thanks! I will try this out! ![]() |