Welcome Guest, Not a member yet? Register   Sign In
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

(This post was last modified: 02-04-2016, 07:54 PM by freddy.)

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




Theme © iAndrew 2016 - Forum software by © MyBB