manikandan170890 / php-form-builder-class

Automatically exported from code.google.com/p/php-form-builder-class
GNU General Public License v3.0
0 stars 1 forks source link

Select options different value than the text #156

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is just a suggestion but it would have been great if the Options of the 
select could have an multidimensional array to hold the text displayed and the 
value separately, so you can actually send for example an id and not the name 
of a record. 

Original issue reported on code.google.com by lordro...@gmail.com on 1 Oct 2011 at 6:03

GoogleCodeExporter commented 9 years ago
Scrap that guys I just saw that the key of the array can be used as the id 
value. It would be a good idea to add it to the documentation, I had to read 
the source. 

Original comment by lordro...@gmail.com on 1 Oct 2011 at 6:08

GoogleCodeExporter commented 9 years ago
Agreed, the documentation as a whole needs to improve.  With limited time to 
devote to this project, this area often gets neglected.  That being said...

Any element that extends the ElementOption abstract class (Select, Checkbox, 
Radio, Sort, Checksort, etc) can accept either a one or two dimensional array 
to represent its options parameter.  If a one dimensional array is passed, the 
value and displayed text will be the same.  For two dimensional arrays, the 
keys will be set as values and the array's values will be used as the displayed 
text.  

It sounds like you discovered this after looking through the source (good for 
you btw for taking the initiative), but I thought I'd quickly re-iterate for 
future readers of this post.

- Andrew

Original comment by ajporterfield@gmail.com on 1 Oct 2011 at 6:28

GoogleCodeExporter commented 9 years ago
Hey guys,

I've tried in so many ways (two-dimentsional array) but could not make it work. 
 Could you please show me some snippets of this code? Thanks.

-Clan

Original comment by cjcl...@gmail.com on 26 Dec 2011 at 3:25

GoogleCodeExporter commented 9 years ago
$form->addElement(new PFBC\Element\Select("Select:", "Select", array(
     "" => "--Select Option--",
     "1" => "Option #1",
     "2" => "Option #2",
     "3" => "Option #3",
)));

Original comment by ajporterfield@gmail.com on 26 Dec 2011 at 5:03