Welcome Guest, Not a member yet? Register   Sign In
Form Helper Label
#1

[eluser]Perkin5[/eluser]
I want to give a label the class of 'required' so I can do:

Code:
$data = array(
'class'=>'required'
);
echo form_label('First Name','',$data);

but for a single attribute, it doesn't seem worth using an array. So I tried:

Code:
echo form_label('First Name','','class="required"');

but it doesn't work. A simlar approach works with other form helper elements so why doesn't this work? Or how can it be made to work?
#2

[eluser]CroNiX[/eluser]
Extend the form_helper with your own form_label() function. Looking at the code, it seems pretty easy to do what you are wanting there.
#3

[eluser]Perkin5[/eluser]
Gulp! That would be a first for me...
#4

[eluser]CroNiX[/eluser]
Read the Extending Helpers section. It's pretty easy (as is extending just about everything in CI).
#5

[eluser]Perkin5[/eluser]
OK - thanks
#6

[eluser]InsiteFX[/eluser]
Just p[ass it the css class name in $str
Saveas: ./application/helpers/MY_form_helper.php
Code:
// ------------------------------------------------------------------------

/**
* Form Label Str Tag
*
* @access public
* @param string The text to appear onscreen
* @param string The id the label applies to
* @param string Additional class str
* @return string
*/
if ( ! function_exists('form_label_str'))
{
    function form_label_str($label_text = '', $id = '', $str = '')
    {
        $label = '<label class="'.$str.'"';

        if ($id != '')
        {
            $label .= " for=\"$id\"";
        }

        $label .= ">$label_text</label>";

        return $label;
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB