Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7543927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:33:20+00:00 2026-05-30T08:33:20+00:00

(Edit: I’ve since realised that perhaps it’s not possible to pass arrays as parameters

  • 0

(Edit: I’ve since realised that perhaps it’s not possible to pass arrays as parameters in callbacks?)

I’m trying to work out how to pass parameters to a callback function in CI. I’ve read the documentation but there isn’t much on the subject except:

To invoke a callback just put the function name in a rule, with
“callback_” as the rule prefix. If you need to receive an extra
parameter in your callback function, just add it normally after the
function name between square brackets, as in: “callback_foo[bar]”,
then it will be passed as the second argument of your callback
function.

What I’m trying to do is create a callback which checks if an has been selected which shouldn’t have been. So if someone selects the option which says “Please select” it won’t be added to the database. Task types is just a table with primary keys and a name field and about 10 rows.

Controller
So here is my controller code (cut down):

function Add_Task()
{
  $task_types_get = $this->task_model->Get_Task_Types();//Get available task types.
  $this->options->task_types = $task_types_get->result();
  $not_selectable = array(1);//Non selectable values for select. Added to callback function below for validation. These are pks.

  $this->form_validation->set_rules("task_type","Task Types","required|callback__Not_Selectable[$not_selectable]");

  if($this->form_validation->run())
  {
     //Add to db etc..
  }
}

Callback
And my callback to check if something is not selectable:

function _Not_Selectable($option,$values=array())
{  
  if(in_array($option,$values))//Is the value invalid?
  {
    $this->form_validation->set_message('_Not_Selectable', 'That option is not selectable.');
    return false;
  }
  return true;
}

View
The data which is coming back from the model is ok, but there are not validation errors. My view is as follows:

<? $this->load->view('includes/header'); ?>

  <?=form_open();?>

  <div class="form_row">
    <div class="form_field">
      <label for="task_desc">Task Type</label>
    </div>

    <div class="form_field name_element" id="name-list">
      <select name="task_type" id="task_select">
        <? foreach($task_types as $t => $v):
             echo "<option ".set_select('task_type', $v->tt_id)." value=\"{$v->tt_id}\">{$v->name}</option>\n";
           endforeach;
        ?>
      </select>
      <?=form_error('task_type');?>
    </div>
  </div>

  <?=form_submit('add_task', 'Add Task');?>

  <?=form_close();?>

<? $this->load->view('includes/footer'); ?>

Errors
The error I’m getting is:

A PHP Error was encountered
Severity: Warning
Message: in_array() [function.in-array]: Wrong datatype for second argument
Filename: controllers/tasks.php
Line Number: 112 (NOTE: this is the in_array line in the callback function.)

The error suggests that the information passed is not an array but I’ve even defined array as default. I did a print_r() on the $options array in the callback function but it just printed out an empty Array.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:33:21+00:00Added an answer on May 30, 2026 at 8:33 am

    The problem is here:

    "required|callback__Not_Selectable[$not_selectable]"
    

    This translates to the string:

    "required|callback__Not_Selectable[Array]"
    

    This is what happens when you treat arrays as strings in PHP.

    This problem is a limitation of Codeigniter’s form validation library, there is no proper way to use arrays in callbacks or validation rules, you’ll have to use strings. Try this:

    $not_selectable = implode('|', $your_array);
    

    This will make something like 1|4|18|33. Then set your rules as you are currently doing, but in your callback be prepared for a pipe delimited string rather than an array, and use explode() to create one:

    function _Not_Selectable($option, $values_str = '')
    {  
      // Make an array      
      $values = explode('|', $values_str);
    
      if(in_array($option,$values))//Is the value invalid?
      {
        $this->form_validation->set_message('_Not_Selectable', 'That option is not selectable.');
        return false;
      }
      return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
EDIT: Sorry about ellipsis that's not what I actually have. For declaring an array
Edit: From another question I provided an answer that has links to a lot
Edit: an important piece might be that I'm calling a cfc method via ajax...
EDIT: it is necessary for this to be a series of 1d Arrays. 2d
--EDIT-- I believe this is a valid question that may have multiple answers (as
EDIT: When I merge link_def.cpp with link_dec.h, I only get the first error, not
EDIT I tried debugging this with xdebug and netbeans. It's weird that the exports
EDIT : Summary : Git does not allow dates before 1973/03/03 09:46:40 (epoch+100000000s) given
Edit : Array should be CvMat or IplImage is not an error message specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.