PHP Classes

Values returned from SELECt

Recommend this page to a friend!

      Wizard  >  All threads  >  Values returned from SELECt  >  (Un) Subscribe thread alerts  
Subject:Values returned from SELECt
Summary:Value returned for SELECT fields is index - alternatives?
Messages:4
Author:Tom Ransom
Date:2005-04-21 05:23:31
Update:2005-05-06 05:40:05
 

  1. Values returned from SELECt   Reply   Report abuse  
Picture of Tom Ransom Tom Ransom - 2005-04-21 05:23:31
For SELECT-type fields, it appears the class returns an index (0 ...) of the options. Is there a way that I haven't figured out to have Select fields return a "Value" - eg <option value="December" selected>December</option>

But otherwise love this class as it solves a couple of UI problems I was facing.

- Tom

  2. Re: Values returned from SELECt   Reply   Report abuse  
Picture of Dean Mumby Dean Mumby - 2005-04-30 20:33:56 - In reply to message 1 from Tom Ransom
Hi

All you need to do afaik is pass an array to the options field

eg: $companies = array( three => 'three', five => 'five');

Good Luck
Dean

  3. Re: Values returned from SELECt   Reply   Report abuse  
Picture of Dave Dave - 2005-05-03 10:21:45 - In reply to message 2 from Dean Mumby
Quite correct:

pass the array in a hash form, where the indeces of the array aren't numeric, and you will definately get the desired result.

The genopts function attempts to figure out whether or not an array is a has array, but it's a bit of a fudge, so there are some ways you can help it:

1) specify the "hash" key in the optional extra array that you can pass to the addinput function. The extra array holds little bits of information that pertain to particular input types. You just add it as an element of the definition array:
$foo->addinput(array(
...
"extra" => array("hash" => 0)
);
Note that I specified hash *off* -- if you don't want to give hash-style indeces for the options array, you just need to make sure that the wizard class knows that the options array is definately not a hash array -- in that case, the value of each element of the options array is used for both the visible value and the passed value in a select tag.

2) actually make the array to be a hash array (as mentioned as the original solution to the problem).

The genopts function tries to do this for you, but your milage may vary. In theory, it's simple: the numeric value of an element's key should be equal to that key. If not, then the array is a hash array. This idea of mine, although it seems fine in theory, may not be perfect, so you may want to resort to either explicitly using a hash array, or explicitly telling the wizard class that the options array is not a hash.

hope this helps!
-d

  4. Re: Values returned from SELECt   Reply   Report abuse  
Picture of Tom Ransom Tom Ransom - 2005-05-06 05:40:05 - In reply to message 3 from Dave
Thanks guys - that worked and made sense as soon as I stopped to think about it.

Dave - you may want to add an example of a "hashed" option array to your sample included with the Class.

I am working happily with this class and have several projects that will benefit from its inclusion.

- Tom