CodeIgniter Forums
form_open attributes string bug - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: form_open attributes string bug (/thread-52147.html)

form_open attributes string bug - El Forum - 05-31-2012

The form_open helper function doesn't cope with json_encoded data.

When adding custom data-x attributes to any element, my understanding is that it's quite usual to use single quotes and to json encode the value because json_encoded data will have double quotes in it.

$html = '<a href="/">Bar</a>';
// I did add
// data-foo=\''.json_encode($foo_array).'\'
// to the above tag but code parser has stripped it out.

The form_open helper function accepts an array of key=>value pairs for adding attributes to the form tag. It double-quotes all values in the resulting string which breaks custom data attributes like this.

There is a workaround of passing a string instead of an array but that's clearly more cumbersome than using an array.

Is there any possibility or need to alter the helper function such that it either single-quotes data attributes or checks for quotes in the value and switches where necessary.