Re: [Phphtmllib-devel] Usability issues
Status: Beta
Brought to you by:
hemna
From: Tim M. <mo...@mr...> - 2002-06-06 20:30:47
|
Walter A. Boring IV wrote: >>Another API change that I suggested before is switching the label and >>value in the form_select() convenience function. It would allow calls >>like this: >> >> $form = form_select('example', ('zero', 'one', 'two')); >> >>rather than this: >> >> $form = form_select('example', (0=>'zero', 1=>'one', 2=>'two')); >> >>The patch for this is simply: >> >>--- phphtmllib.orig/tag_utils/form_utils.php Fri Apr 5 14:29:45 2002 >>+++ phphtmllib/tag_utils/form_utils.php Tue Apr 23 21:02:01 2002 >>@@ -294,7 +294,7 @@ >> >> $select = new SELECTtag( array("name" => $name) ); >> >>- while( list($label, $value) = each($options) ) { >>+ while( list($value, $label) = each($options) ) { >> $selected_value = ""; >> if ($value == $selected) { >> $selected_value = "SELECTED"; > > > ---ah yes. I think you have wanted this one for a while no? Since 1.0.2 but it's easy enough to change as each new version is released. =) > Switching the array to be value=>label would make it easier to read in > the cases where the value is an int 0,1,2,3. But in the cases where > its some string it seems to make more sense to have it label=>value > > so you would do > array("California" => "CA", "Texas" => "TX"); > instead of > array("CA" => "California", "TX" => "Texas"); >> to give u > > <select ...> > <option value="CA">California</option> > <option value="TX">Texas</option> > </select> > > thoughts? I think you have this reversed. The change I suggested would accept array("CA" => "California", "TX" => "Texas") to provide the HTML output you gave. To be explicit, this $select = form_select('test', array('CA' => 'California', 'TX' => 'Texas')); echo $select->render(); gives you this <SELECT name="test"><OPTION value="CA" >California</OPTION> <OPTION value="TX" >Texas</OPTION></SELECT> To answer your question... If you are using strings, you have to enter both strings anyway and the order doesn't matter (at least no to me). If you are using integers, it makes sense to use the array index as the value so you only have to enter the string. This just makes the job a little easier where it can and adds no extra work where it can't. -- Tim Moloney ManTech Real-time Systems Laboratory 2015 Cattlemen Road \ / Sarasota, FL 34232 .________\(O)/________. (941) 377-6775 x208 ' ' O(.)O ' ' |