Welcome Guest, Not a member yet? Register   Sign In
input->post() and the "isset()" function
#1

[eluser]jinfusion[/eluser]
All,

The following code:

Code:
if(isset($this->input->post('foods')) && $this->input->post('foods') == '0')
            {
                $_SESSION['error'] = "<div class='error'>You must select something from the Foods menu.</div>";
                $this->select_food();
            }

produces the following error:

Quote:Fatal error: Can't use method return value in write context in {path to file...} on line 126
Line 126 is the first line, the IF statement.

Is there a way to check the post vars in CI other then just accessing the POST superglobal directly? (which does not produce the error), I like to stay within the framework where possible for clarity's sake.

Joel
#2

[eluser]garymardell[/eluser]
$this->input->post('some_data');

The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist.

From the userguide. So you need not use the isset function and just see if it is not false.
#3

[eluser]jinfusion[/eluser]
Brilliant! Thanks. I forgot how well thought out these things are in CI.
#4

[eluser]guidorossi[/eluser]
I think you should use the form validation class for this.

Something like

Code:
$this->form_validation->set_rules('foods', 'Foods', 'required|callback_value_check');

and then

Code:
function value_check($str)
    {
        if ($str == '0')
        {
         $this->form_validation->set_message('value_check', 'You must select something from the Foods menu.');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
#5

[eluser]jinfusion[/eluser]
This is a modal dialog not triggering postbacks. I have had some trouble getting the last leg (no view) to work right so I decided to roll my own. I would be glad to see an example of a asynchronous multi stage wizard with the Validation class.
#6

[eluser]dalirnet[/eluser]
Code:
if($this->input->post('search') != false)
{
     // isset true
}




Theme © iAndrew 2016 - Forum software by © MyBB