1

codeigniter override set_value function in form helper using MY_helper to repopulate fields at get,post both and while not validating. i am using version of ci is 2.0.3 i created My_form_helper.php in application/helpers/ and added function

function set_value($field = '', $default = '')
{   
    if (FALSE === ($OBJ =& _get_validation_object()))
    {
        if (isset($_POST[$field]))
        {
            return form_prep($_POST[$field], $field);
        }
        if (isset($_GET[$field]))
        {
            return form_prep($_GET[$field], $field);
        }

        return $default;
    }

    return form_prep($OBJ->set_value($field, $default), $field);
}

but its not working.

in autoload.php i am doing this -> $autoload['helper'] = array('html','form','url','my','text','MY_form'); it says unable to load my_form_helper.php

amolv
  • 978
  • 1
  • 8
  • 20

1 Answers1

0

There seems to be some problem with Capital letters in helper file names. It appears that codeigniter converts helper names to all lowercase and then finds the file.

Try helper file: my_form_helper.php and then check. It should work.

Vikk
  • 3,353
  • 3
  • 22
  • 24
  • yes it is, in custom helper we create instance is that kind of thing needed in above function, there directly isset($_GET[$field]) used. – amolv Oct 28 '11 at 12:26
  • I didn't quite understand your comment but my answer was pertaining to CodeIgniter complaining "unable to load my_form_helper.php". It might be because you have capital letter in your helper file name. Try changing it to all lowercase and CodeIgniter should be able to load it. – Vikk Oct 28 '11 at 13:13
  • oho please have a look at function, hint: in helper we don't use $this like in view/controller – amolv Oct 28 '11 at 14:33