CodeIgniter’s Form Helper doesn’t respect POST arrays

I’ve been working on my first ‘proper’ CodeIgniter project this week. It’s been quite gruelling, as there are some moments where I have definitely sped up my production. But it’s constantly getting hampered by the learning curve. It may be slight, but is frustrating when I hit a wall.

One issue that just cam up is that I want to send multi-dimensional post data to the set_value function in the Form Helper. As you’re passing a string, the array is completely disregarded, and you’re left with nothing.

I’ve created an extension to the helper to temporarily get around the problem until I can look at it and fix it properly:

MY_form_helper.php

<code>

<?php
if ( ! function_exists('set_value_arr'))
{
	function set_value_arr($field = '', $id = '0', $default = '')
	{
		if (FALSE === ($OBJ =& _get_validation_object()))
		{
			if ( ! isset($_POST[$field][$id]))
			{
				return $default;
			}

			return form_prep($_POST[$field][$id]);
		}

		return form_prep($OBJ->set_value($field, $default));
	}
}

?></code>

This sets a second parameter as the array index. This way, you should be able to access form elements sent into the POST array as arrays themselves.