CodeIgniter Forums
Form Validation and Arrays - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Form Validation and Arrays (/showthread.php?tid=64298)



Form Validation and Arrays - coldlamper - 02-04-2016

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


RE: Form Validation and Arrays - freddy - 02-04-2016

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 !


RE: Form Validation and Arrays - Wouter60 - 02-05-2016

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.