Jump to content

input empty or not


Matthias
 Share

Recommended Posts

I have a strange one. inside my module class i want to check the user input, but it does not work like expected. Trying around since hours … what am i doing wrong. Any idea?

I have a form, method=post, posting a simple text input "input_name".

<?php
    public function ready()
    {
        echo $this->input->post->input_name; // echoes the name
        
        if (empty($this->input->post->input_name)) {
            echo 'no name'; // echoes "no name", too
        }
      
        $foo = $this->input->post->input_name;
        if (empty($foo)) {
            echo 'no name'; // echoes nothing, works.
        }
}

?>

The "empty" term seems not to work. Im going crazy with this (or $this …)! Is it something about namespaces? PHP7? 

Any ideas?

Thanks a lot!

 

 

 

 

Link to comment
Share on other sites

Hi Zeka, thanks a lot for the links.

I switched in my MAMP between PHP 5.6 and 7 and 

if(empty($input->post->name)) { ... }

works only in PHP 5.6 not in PHP 7. For whatever reasons, couldn’t find anything about this in the PHP Docs. 

Yes, I'll change to the even simpler
 

if($input->post->name) { ... }


And say byebye to "empty" ;-)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...