• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form Validation and Arrays

#1
How can I check if a post variable is an array?
If I try this:

$this->form_validation->set_rules('data[]', 'Post Data', 'is_array');

It checks all the array elements with is_array. I want to check if 'data' is an array.

Any ideas?

Thanks,
Brian
Reply

#2
well you talk about how to check variable post in array, don't you ? so i will not disscuss about validation ya,

please check here just tested in yours, cause it working for me

Code:
$itemName = $this->input->post('your input type name');
if (is_array($itemName))
{
//do your own code bro, here is array !
} else
{
//stop it's not array
}

Hope this help you !
Reply

#3
Once you call form validation for a field with square brackets, you already seem to know it's an array, don't you?
I guess your form contains multiple fields with name="data[]".
These fields are posted as an array.
In your form validation routine, you must check which of those have a value or not.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.