CodeIgniter Forums
Form Extension for DMZ 1.8.1 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Form Extension for DMZ 1.8.1 (/showthread.php?tid=42638)



Form Extension for DMZ 1.8.1 - El Forum - 06-14-2011

[eluser]theprodigy[/eluser]
I have built a little extension for DMZ 1.8.1.

It creates the array needed for CodeIgniter's form_dropdown. It doesn't create the drop down itself, so you still need to use the Form Helper, but this will create the array from your object, that CodeIgniter needs for that function.

Example Code:
Code:
$books = new book();
$books->get();
form_dropdown('book',$books->to_dropdown_array('title'));
//just pass in the string value of the field you want to use as the text of the options

$books = new book();
$books->get();
form_dropdown('book',$books->to_dropdown_array(array('binding'=>'title')));
// pass in an assoc array, with key being field to use for grouping, and value being the field to use for text of the options

$books = new book();
$books->get();
form_dropdown('book',$books->to_dropdown_array(array('author.name'=>'title')));
// pass in an assoc array, with key being dot notation of related model [dot] field (for the grouping), and value being the field to use for the text of the options.

Explanation of parameters:
This plugin takes 2 parameters:
1. string or array.
- If you pass in a string, that string needs to be the name of the field you wish to use for the dropdown. You will receive a regular non-grouped dropdown from CI's form helper.
- If you pass in an array, it needs to be an assoc array, with the key being the field to group the items on, and the value being the field you want to use for the options.
- - If the key is dot notated (author.name), then the part before the [dot] will be the related model, and the part after the dot will be the field in that related model to use as the grouping (in this case, the books will be listed, grouped by author's names.

2. string [optional].
- The second optional parameter is what to use as the value of each option (what gets passed through POST when that option is selected). It needs to be the field of the object.
- Example:
Code:
//using specified id
$books = new book();
$books->get();
form_dropdown('book',$books->to_dropdown_array('title','isbn'));
// in this case, the title will be what is shown (the text of the option), and the ISBN number associated with that record will be the value of each option

I am only listing this here to let you all know about it. You can download it, and ask any questions on my site. The direct link to the page is: here.

Looking forward to reading your comments and answering any questions / bug reports you have.