Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Maintain menu value - help.. anyone???

Quote Reply
Maintain menu value - help.. anyone???
I've tried the LinksSQL and Perl forums with no luck - can ANYONE help me figure this out?

I've put the following pull down menu values in the add and add failure sub routines (Links SQL) in html_templates, but when the add failure template is called it's just displaying the menu value passed to it as text, instead of returning the pull-down menu with the users selection preserved. Can anyone give me a pointer on how to get it to return the error page with their selection perserved but in the pull-down menu?

Thanks, Regan.

sub site_html_add_failure {
# --------------------------------------------------------
# This routine determines how the add failure page will look like.
#
my ($tags, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
(ref $tags eq 'HASH') or croak "HTML_TEMPLATES: Argument '$tags' must be hash reference";

my $linktype .= qq|
<SELECT NAME="Link_Type">\n
<option value="">Select One...\n
<option value="Business">Business\n
<option value="Non-profit">Non-profit\n
<option value="Personal">Personal\n
<option value="Club/Org">Club/Org\n
<option value="Government">Government\n
</select>\n
|;

defined $dynamic and &load_user ($dynamic, $tags);
my $output = &load_template ('add_error.html', {
Link_Type => $linktype,
%$tags,
%GLOBALS
}, undef, $template);
defined $dynamic and &clean_output($dynamic, \$output);
print $output;
}

Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
Take a look at sub get_category_list

You want to pass in a line:

while (($id, $name) = $sth->fetchrow_array) {
($id == $value) ? ($output .= "<option value='$id' SELECTED>$name") : ($output .= "<option value='$id'>$name");
}

Where the value passed back by the user is used to flag the selected option.

You probably really want to clone this routine, and set it up to deal with your chosen select list. Pass it the parameter you want selected, and have it return the list in a tag you can use just like <%category%>


PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
Why not use sub build_select_field since she has already defined the field in the %db_select_fields hash????

Regards,

Eliot Lee
Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
That's more limited, and assumes all the values are enumerated in the database and .def file.

If you use the new subroutine route, the list of features can be dynamic, pulled from a database, or passed in, or hard coded.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
Thanks for your suggestions, but i've got no idea how to modify those subroutines to work :(

I've just done this hack which is working, but obviously it isn't using the Link def file - which would be nicer as the menu selection list would then be automatically updated when the database (and def file) is added to.

If anyone has time could they post how to do this the correct way? Getting the info from the Links def file?

Thanks.


sub site_html_add_failure {
# --------------------------------------------------------
# This routine determines how the add failure page will look like.
#
my ($tags, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
(ref $tags eq 'HASH') or croak "HTML_TEMPLATES: Argument '$tags' must be hash reference";

my %LIST = (
'' => 'Select One...',
'Business' => 'Business',
'Non-profit' => 'Non-profit',
'Personal' => 'Personal',
'Club/Org' => 'Club/Org',
'Government' => 'Government'
);

my ($linktypelist, $key, $output);

$output = "<SELECT NAME='Link_Type'>";
while (my ($key, $value) = each %LIST) {
if ($tags->{'Link_Type'} eq "$key"){ $output .="<option value='$key' SELECTED>$LIST{$key}\n";}
else { $output .="<option value='$key'>$LIST{$key}\n";}
}
$output .= "</select>";


defined $dynamic and &load_user ($dynamic, $tags);
my $output = &load_template ('add_error.html', {
Link_Type_List => $output,
%$tags,
%GLOBALS
}, undef, $template);
defined $dynamic and &clean_output($dynamic, \$output);
print $output;
}

Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
Is Link_Type an enumerated field in your database?

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
I set Link_Type up with MySQLman as a type enum;

enum('Business','Non-profit','Personal','Club/Org','Government')

- is that what you meant?

Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
Yes,

If you did that, follow the example and edit the Links.def file to display the tags.

I haven't played with this much, as I tend to try to do much of the stuff in a module or routine specific for what I need, rather than having to re-edit .def files.

If you wanted, it shouldn't be too hard to pull the values of the mySQL enum field in each run, so you always have an up to date list.



PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
Thanks Pugdog, I'll give it a go and see if I can figure it out!

Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
Check out the following Thread:

http://www.gossamer-threads.com/...ew=&sb=&vc=1

Regards,

Eliot Lee
Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
Brilliant Eliot!!!!!!

Worked a treat - exactly what I was after!

Regan.

Quote Reply
Re: Maintain menu value - help.. anyone??? In reply to
You're welcome.

I actually took a different approach and created additional tables for common data that I am storing in my databases. Then I simply copied the appropriate subs in the DB_Utils.pm. This allows me to update the values for drop-downs more easily than editing the HTML_Templates.pm file all the time.

Regards,

Eliot Lee