Gossamer Forum
Home : Products : DBMan : Customization :

Chop Select list options

Quote Reply
Chop Select list options
My select field options were; 'Yes' and 'No', I need to change them to; 'No - not at this time' and "Yes - send me more information.... '.

I want the database to store only the Yes and No. I read about Perl's chop, is this a valid approach?
Or am I better off just storing the entire string "No - not at this time" in the database? I can see that I may run into problems getting the Build_select_field to show the correct value for existing records if the "No" in the database is not one of the options in the build_select_field.

Below I found on the unofficial FAQ, thanks! It works but I am interested in a better way.
*******************************************************************
Question:

Let's say My user can choose "Male" or "Female" in their input.
But I just want to print out "M" or "F" instead of the whole word.
----------------------------------------------------------
Response: JPDeni

There are several ways to do this.

Probably the easiest way would be to add a couple of lines to your default.cfg file:

$gender{'Male'} = "M";
$gender{'Female'} = "F";

You really can put the lines anywhere you want to in the script. I'd probably put them somewhere around
where the radio fields are defined.

Then, in html_record, where you want to print out the gender, use

$gender{$rec{'Gender'}}

Change the Gender above to the actual field name you're using for the field.

There are other ways to do it, too -- using "if" statements or just printing out the first letter,
but that requires a little more understanding of Perl.
------------------
JPD