Gossamer Forum
Home : Products : DBMan : Customization :

Search form select fields

Quote Reply
Search form select fields
Hi all Esp JPDeni, Smile

Another Qusestion Frown, I would like to have the following select field from the search form, problem is that the $ sign makes the numbers a varialbe. Is there a way to format this select field so that the dollar sign can be included in html.pl ?

<select name="Price-gt">
<option value="0">$0</option>
<option value="9999">$10,000</option>
<option value="19999">$20,000</option>
<option value="29999">$30,000</option>
<option value="39999">$40,000</option>
<option value="49999">$50,000</option>
<option value="59999">$60,000</option>
<option value="69999">$70,000</option>
<option value="79999">$80,000</option>
<option value="89999">$90,000</option>
</select>

One more question, if I wanted to define the select box in the cfg file is it possible to give both the above values to the field. eg.

<option value="29999">$30,000</option>

so that not only the 29999 is displayed.
I have ways around this, if it is not possible.

As always, help greatly appreciated from Perth, Western Australia. Smile
Quote Reply
Re: Search form select fields In reply to
The "\" in perl designates that a "reserved" character which has special meaning in perl (like the $ indicating a string) should actually be used as the character itself.

Therefore if you replace the "$" with "\$", the dollar signs will appear.

I don't quite understand your second question. If I am interpreting you correctly, you don't want 29,999 to show up when you print out the value of the field. Instead you want the field to print out $30,000 if the field is 29999. Please post a clarification here so I don't spend time on something useless to you.



[This message has been edited by Lauren Stegman (edited July 01, 1999).]
Quote Reply
Re: Search form select fields In reply to
Hi Lauren,


Of course, would you believe I was using a "/" doh..
Thanks for your reply. Regarding my second problem, yes I would like to be able to create a select list that has the value set as 29999 and displays $30,000 in the list

<option value="29999">$30,000</option>

In the cfg file under %db_select_fields it only offers the choice of setting and displaying the same number.

Berths => '10000,29999,39999' etc

Thanks Lauren Smile,
I'll try the first problem again.

[This message has been edited by fordy (edited July 01, 1999).]
Quote Reply
Re: Search form select fields In reply to
I used made a subroutine for a client that I called a "fancy select field" (the only thing I could think of at the time Smile ) which would create a field with a value different from what is seen in the select list.

I set up the field definition right in the subroutine, but you could probably set it up in the .cfg file.

Code:
sub build_fancy_select_field {
# --------------------------------------------------------
#
# To call this subroutine from html_record_form, use the following syntax:
#
# print &build_fancy_select_field("FieldName",$rec{'FieldName'});
#
# Be sure to express the field name *exactly* as it is defined in your .cfg file.
#

my $field = $_[0];
my $compare = $_[1];

my %selector = (
'FieldName1' => [
['---','Select'],
['Value1','Selection1'],
['Value2','Selection2'],
['Value3','Selection3']
],
'FieldName2' => [
['---','Select'],
['Value1','Selection1'],
['Value2','Selection2'],
['Value3','Selection3']
],
'FieldName3' => [
['---','Select'],
['Value1','Selection1'],
['Value2','Selection2'],
['Value3','Selection3']
]
);
$output = qq|<SELECT NAME="$field">\n|;
$i = 0;
while ( $selector{$field}[$i][0] ) {
$selector{$field}[$i][0] eq $compare ?
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]" SELECTED>$selector{$field}[$i][1]\n|) :
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]">$selector{$field}[$i][1]\n|);
++$i;
}
if ($i) { $output .= "</SELECT>"; }
else { $output = "Incorrect field definition"; }
return $output;
}




------------------
JPD







[This message has been edited by JPDeni (edited July 01, 1999).]
Quote Reply
Re: Search form select fields In reply to
Thanks Lauren and Carol,

What can I say. Your help is great. Smile Smile Smile

I will try your suggestion Carol, I'm sure it will work.

Kind Regards Fordy.
Quote Reply
Re: Search form select fields In reply to
Great mod, Carol!

However, there is one minor (yet not so minor in running the script) syntax error:

Code:
print &build_fancy_select_field("FieldName",$rec{'FieldName'})

should be closed with a ;

Code:
print &build_fancy_select_field("FieldName",$rec{'FieldName'});

Very minor though...more adept programmers should know how to fix this, but for those novices and intermediate programmers, it is a mistake that would take a few hours to fix.

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Search form select fields In reply to
Thanks for noticing. I made the change in the script.


------------------
JPD





Quote Reply
Re: Search form select fields In reply to
Hi JPDeni, just one more question Wink. How do I define greater than/less than in these select fields. Before I was using a html search form from outside the database and naming two fields for say price as price-lt and price-gt.

Thankyou for your help so far.


[This message has been edited by fordy (edited July 01, 1999).]
Quote Reply
Re: Search form select fields In reply to
You can to that with this one, too

Code:
my %selector = (
'Price-gt' => [
['---','Greater Than'],
['9999','$10,000'],
['19999','$20,000'],
['29999','$30,000']
],
'Price-lt' => [
['---','Less Than'],
['10001','$10,000'],
['20001','$20,000'],
['30001','$30,000']
]
);

I think you'll be able to use the $ signs without having to escape them with a \. Just a sec and I'll check it.

Yep. If you use the single quotes around each of the entries, you can just enter them as I have them above.


------------------
JPD





Quote Reply
Re: Search form select fields In reply to
Hi JPDeni,

I did try similar to that. It's a great mod although I still can't get the Price-gt and Length-gt fields to work. I get the 'incorrect field definition' error message I have looked over the code:

Code:
<tr>
<td align="Right" valign="TOP" width="158"><$font>Length:</td>
<td valign="TOP" width="498"> ~; print &build_fancy_select_field("Length-gt","$rec{'Length'}");
print &build_fancy_select_field("Length-lt","$rec{'Length'}");
print qq~</td>
</tr>
<tr>
<td align="Right" valign="TOP" width="158"><$font>Price:</td>
<td valign="TOP" width="498"> ~; print &build_fancy_select_field("Price-gt","$rec{'Price'}");
print &build_fancy_select_field("Price-lt","$rec{'Price'}");
print qq~</td>
</tr>

and can't find the error.
These are my field definitions:

Code:

'Length-lt' => [

['200','No Maximum'],
['1','1'],
['2','2'],
['3','3'],
['4','4'],
['5','5'],
['6','6'],
['7','7'],
['8','8'],
['9','9'],
['10','10'],
['11','11'],
['12','12'],
['13','13'],
['14','14'],
['15','15'],
['16','16'],
['17','17'],
['18','18'],
['19','19']],

'Length-gt' => [

['0','No Minimum'],
['1','1'],
['2','2'],
['3','3'],
['4','4'],
['5','5'],
['6','6'],
['7','7'],
['8','8'],
['9','9'],
['10','10'],
['11','11'],
['12','12'],
['13','13'],
['14','14'],
['15','15'],
['16','16'],
['17','17'],
['18','18'],
['19','19']],

'Price-lt' => [

['99999999','No Maximum'],
['1','$1'],
['2','$2'],
['3','$3'],
['4','$4'],
['5','$5'],
['6','$6'],
['7','$7'],
['8','$8'],
['9','$9'],
['10','$10'],
['11','$11'],
['12','$12'],
['13','$13'],
['14','$14'],
['15','$15'],
['16','$16'],
['17','$17'],
['18','$18'],
['19','$19']],

'Price-gt' => [

['0','No Minimum'],
['1','1'],
['2','2'],
['3','3'],
['4','4'],
['5','5'],
['6','6'],
['7','7'],
['8','8'],
['9','9'],
['10','10'],
['11','11'],
['12','12'],
['13','13'],
['14','14'],
['15','15'],
['16','16'],
['17','17'],
['18','18'],
['19','19']]


Thanks Fordy.
Quote Reply
Re: Search form select fields In reply to
You do have

my %selector = (

before your definitions

and

);

at the end, right?

Are you defining them within the subroutine or in separately. I didn't think about this before, but if you're defining them in the .cfg file, you'll need to take off the "my" part. So that the definition starts with

%selector = (

That's the only thing I can think of right now.

If that doesn't fix it, try commenting out the

else { $output = "Incorrect field definition"; }

line. (Put a # at the beginning of the line). See if that works.


------------------
JPD





Quote Reply
Re: Search form select fields In reply to
Sorry JPDeni, Iv'e tried all you said, still no sucess.

Here's the full code:


Code:

sub build_fancy_select_field {

# To call this subroutine from html_record_form, use the following syntax:
# print &build_fancy_select_field("FieldName",$rec{'FieldName'});

# Be sure to express the field name *exactly* as it is defined in your .cfg file.

my $field = $_[0];
my $compare = $_[1];
%selector = (

'Length-lt' => [

['200','No Maximum'],
['1','1'],
['2','2'],
['3','3'],
['4','4'],
['5','5'],
['6','6'],
['7','7'],
['8','8'],
['9','9'],
['10','10'],
['11','11'],
['12','12'],
['13','13'],
['14','14'],
['15','15'],
['16','16'],
['17','17'],
['18','18'],
['19','19']],

'Length-gt' => [

['0','No Minimum'],
['1','1'],
['2','2'],
['3','3'],
['4','4'],
['5','5'],
['6','6'],
['7','7'],
['8','8'],
['9','9'],
['10','10'],
['11','11'],
['12','12'],
['13','13'],
['14','14'],
['15','15'],
['16','16'],
['17','17'],
['18','18'],
['19','19']],

'Price-lt' => [

['99999999','No Maximum'],
['1','$1'],
['2','$2'],
['3','$3'],
['4','$4'],
['5','$5'],
['6','$6'],
['7','$7'],
['8','$8'],
['9','$9'],
['10','$10'],
['11','$11'],
['12','$12'],
['13','$13'],
['14','$14'],
['15','$15'],
['16','$16'],

['17','$17'],
['18','$18'],
['19','$19']],

'Price-gt' => [

['0','No Minimum'],
['1','1'],
['2','2'],
['3','3'],
['4','4'],
['5','5'],
['6','6'],
['7','7'],
['8','8'],
['9','9'],
['10','10'],
['11','11'],
['12','12'],
['13','13'],
['14','14'],
['15','15'],
['16','16'],
['17','17'],
['18','18'],
['19','19']]

);
$output = qq|<SELECT NAME="$field">\n|;
$i = 0;
while ( $selector{$field}[$i][0] ) {
$selector{$field}[$i][0] eq $compare ?(
$output .= qq|<OPTION VALUE="$selector{$field}[$i][0]" SELECTED>$selector{$field}[$i][1]\n|):
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]">$selector{$field}[$i][1]\n|);
++$i;
}
if ($i) { $output .= "</SELECT>"; }
else { $output = "Incorrect field definition"; }
return $output;
}

Code:

<tr>
<td align="Right" valign="TOP" width="158"><$font>Length:</td>
<td valign="TOP" width="498"> ~; print &build_fancy_select_field("Length-gt",$rec{'Length'});
print &build_fancy_select_field("Length",$rec{'Length'});
print qq~</td>
</tr>
<tr>
<td align="Right" valign="TOP" width="158"><$font>Price:</td>
<td valign="TOP" width="498"> ~; print &build_fancy_select_field("Price-gt",$rec{'Price'});
print &build_fancy_select_field("Price-lt",$rec{'Price'});
print qq~</td>
</tr>

Code:
Length => [5, 'alpha', 5, 5, 0, '', ''],

Price => [23, 'numer', 12, 12, 0, '', ''],



When I comment out the error line it still displays the select box with the values outside it.

Will keep at it,

Thanks Fordy. Smile

[This message has been edited by fordy (edited July 01, 1999).]

[This message has been edited by fordy (edited July 01, 1999).]
Quote Reply
Re: Search form select fields In reply to
I finally got it!

Instead of having "0" as a value, you need to have "---"

['---','No Minimum'],

You'll get the same results, but the field will work.

Also, in the code you posted, you had

print &build_fancy_select_field("Length",$rec{'Length'});

A typo, I'm sure. This needs to be "Length-lt"

------------------
JPD





Quote Reply
Re: Search form select fields In reply to
Works great Smile Smile Smile Smile.

Sorry I didn't pick that up from your original code. I think I've used up all my thankyou's....

I'm very greatful for your help. Smile


Fordy.
Quote Reply
Re: Search form select fields In reply to
Hi there. I am having a problem with this mod...well, not a problem, but a challenge.
I have installed this mod and it works fine except that when someone searches for a value that are similar (e.g., Music and Music Performance), they get all results that include these two values. I know that this is not directly related to this mod, since this issue has been discussed in other Topics in this Forum (except that I do not have the luxury of time to search through the Forum to find them).

I have come up with a quick and dirty solution, which is to change Music Performance to Mus/Performance. The results do come up for ONLY Music Performance AND Music when you select these values.

Another example is the field,DAYS, which has different combinations of days (Monday through Saturday). The problem is that when someone selects Friday, they get all the results that include Friday, such as 'Monday, Wednesday, Friday' and
'Wednesday, Friday'.

BUT, I was wondering is there a way to fix this so that values selected will ONLY show up and not similar values without having to change the values dramatically. Can this be done within the fancy build mod or in default.cgi?

Also, is there a way to print the "Selection" value rather than the "Field Value" in search results? For instance, when I changed Music Performance to Mus/Performance, I get Mus/Performance in the Search Results.

TIA.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited July 21, 1999).]
Quote Reply
Re: Search form select fields In reply to
Eliot, you have a number of questions there, and I can only deal with one at a time. (Sorry. My brain is getting old. Smile )

Regarding your last question: If you only have one value that is a problem, it's easy to change it.

Just before you print out the field (assuming you are not using the autogenerate feature), add

Code:
if ($rec{'field name'} eq "Mus/Performance") {
$rec{'field name'} = "Music Performance";
}

If you have a bunch of them, it will require a little more coding.

Now what were your other questions?

------------------
JPD







[This message has been edited by JPDeni (edited July 28, 1999).]
Quote Reply
Re: Search form select fields In reply to
Hello, Carol. Glad to see that you are back!
Smile

Anyway, the codes (*) you gave me don't seem to work.

(*)
Code:
if ($rec{'field name[/b]'} eq "Mus/Performance") {
$rec{'field name[/b]'} = "Music Performance";
}

Where do I exactly place them? I tried putting them in a variety of places in the html.pl file, including the "view_success" and "record_long_row" sub-routines...Still have that slash for Mus/Performance.

My main question was is there a way to modify either the fancy mod or default.cgi that will address the problem with similar values of fields showing up in the search results. The problem we are experiencing with our Class Schedules is that when someone selects let's say Friday, they get all results that include Friday, such as Monday, Wednesday, and Friday and Monday and Friday.

Does this make sense?

TIA.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited July 28, 1999).]
Quote Reply
Re: Search form select fields In reply to
I had made a mistake with the UBB code earlier. Sorry 'bout that.

The code would go just before you're going to print out the field.

I don't know how to get it to match on the whole field, which is what you want for the "Friday" problem. That would be a great mod for someone to write or a new feature for the new DBMan that's coming out soon (I hope! Smile ).


------------------
JPD