Atimmer's stories

A blog of a simple dutch web developer.

Mar 10

Kohana input test

I have been busy with making a kohana application and lately I stumbled upon a nasty bug if you don’t know.

What I did was this:

if($this->input->post(‘submit’))

When the form wasn’t send this gave a nasty bug, invisible in production time but still nasty. So I tried this:

if(isset($this->input->post(‘submit’)))

But that gave me a fatal error. Can’t use a function in write context, or something alike. What it meant was that you can only use normal variables in the function isset. Something I didn’t know.

I found the clever but also so simple solution in the Kohana documentation:

if($this->input->post(‘submit’, false))

You give the function the default value of false and all is fine. I think this might help others facing the same problem.