ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

input->post() and the "isset()" function

April 20, 2009 12:50pm

Subscribe [3]
  • #1 / Apr 20, 2009 12:50pm

    jinfusion

    8 posts

    All,

    The following 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:

    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 / Apr 20, 2009 1:06pm

    garymardell

    315 posts

    $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 / Apr 20, 2009 1:56pm

    jinfusion

    8 posts

    Brilliant! Thanks. I forgot how well thought out these things are in CI.

  • #4 / Apr 20, 2009 2:52pm

    guidorossi

    68 posts

    I think you should use the form validation class for this.

    Something like

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

    and then

    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 / Apr 20, 2009 3:43pm

    jinfusion

    8 posts

    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 / Aug 07, 2014 2:51pm

    dalirnet

    17 posts

    if($this->input->post('search') != false)
    {
         // isset true
    }
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases