CodeIgniter Forums
Hidden field does not get id - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Hidden field does not get id (/showthread.php?tid=37281)



Hidden field does not get id - El Forum - 01-04-2011

[eluser]Unknown[/eluser]
Long time troller first time poster.

Using the form gen lib and I am having an issue, the hidden field has no ID attr.
Any reason or is there an issue, or work around for this?

Thx.


Hidden field does not get id - El Forum - 01-05-2011

[eluser]Cristian Gilè[/eluser]
Hi flmike,

this is a limittation of the CI form_hidden function not of formgenlib.

In order to have id attribute in your hidden field you have to extends your form helper (http://ellislab.com/forums/viewthread/129280/)

Code:
if ( ! function_exists('form_hidden'))
{
    function form_hidden($name, $value = '', $id = false)
    {
        if ( ! is_array($name))
        {
            return '<input type="hidden" id="'.($id ? $id : $name).'" name="'.$name.'" value="'.form_prep($value).'" />';
        }

        $form = '';

        foreach ($name as $name => $value)
        {
            $form .= "\n";
            $form .= '<input type="hidden"  id="'.($id ? $id : $name).'" name="'.$name.'" value="'.form_prep($value).'" />';
        }

        return $form;
    }
}

Now, formgenlib hidden fields work like a charm.

There is a dedicated forum for formgenlib: http://ellislab.com/forums/viewthread/107861/