Re: retrieving the label of an option element
| From: | Justin Patrin | Date: | Wed, 29 Jun 2005 18:12:38 +0000 |
| Subject: | Re: retrieving the label of an option element | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-19828@lists.php.net to get a copy of this message | ||
On 6/29/05, Cory Syvenky <csyvenky@gmail.com> wrote:
> Thanks Justin.
>
> Are you kidding? Having the option value as the database key and human
> readable text as the label is one of the oldest methods in 'Ye Ole
> Book of Webdev', why else would HTML_QuickForm_select::loadQuery take
> the params that it does? I don't want to have to save redundant
> strings in the database for no good reason. IMHO, this is a serious
> weakness with the QuickForm lib. At least the .net framework allows
> you to access _anything_ that you could possibly want/need.
>
No, I'm not kidding. Sounds like you have a "correct" implementation,
though, and you're using a DB and the DB key is the value. This is
good and correct. However, there is currently no way (IMHO) to pull
option values from a quickform select element. I suggest you either
keep an assoc array handy to convert or query the display value form
the DB for now. (or you can try accessing the private properties of
the element. $el =& $form->getElement('selName'); print_r($el);)
This would IMHO be a good addition to QuickForm. Try adding a feature
rquest for it in the Bug system. This would also be a good thing to
have in our "next gen" form package wishlist:
http://pookey.co.uk/wiki/php/html_fng
Ian: I can't edit your wiki still. Could you add this please?
> These comments are not directed at you Justin, just thoughts coming
> out of my fingers...
>
> PS: Are you the same Justin that posts to the OpenZaurus list?
>
> cS
>
> On 6/29/05, Justin Patrin <papercrane@gmail.com> wrote:
> > On 6/29/05, Cory Syvenky <csyvenky@gmail.com> wrote:
> > > Hi Gang,
> > >
> > > I'm using QuickForm to build a form that emails the data and also
> > > saves it to a MySQL database using MDB.
> > >
> > > I can retrieve the value submitted from my select list of US states,
> > > but I cannot retrieve the label. An example option looks like:
> > >
> > > <option value="11">Hawaii</option>
> > >
> > > I can grab the submitted value with:
> > >
> > > $stateID = htmlspecialchars($form->exportValue('slctState'));
> > >
> > > Instead I want to grab 'Hawaii', the text label for the option.
> > >
> >
> > You can't. Labels are just that, labels. If the value means nothing to
> > you (i.e. you won't use it in anything else anyway) then just put the
> > label as the value as well.
> >
> > --
> > Justin Patrin
> >
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Justin Patrin