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

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?


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

$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 !

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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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