Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Form Names to Form Values

Quote Reply
Form Names to Form Values
One of our columns is a multi-select list of countries
Type = VARCHAR(255)
Form Names is a list of code numbers
Form Values is a list of actual country names

In our search results, we get the the Form Names (ie: the numbers).
What we need is the Form Values (the real names), which is what the default template gives us.

How do we map from Form Names to Form Values?

We have tried looking at sub generate_search_results to see how the default template does it, but we can't follow the program logic.
Quote Reply
Re: [YoYoYoYo] Form Names to Form Values In reply to
You're using a custom template set, I take it? You're right that this is a big problem and there's no built in way to handle it. However (with MUCH help from TheStone) I came up with a solution which has been working perfectly for me. I think the best way to do it is with a global name->value mapping routine which can be placed in a custom perl module so that it's accessible from all templates.

Download the attached perl module and put it in your /path/to/admin/Dbsql directory. Then you can get the form values by using:

<%Dbsql::Custom::display('column_name')%>

FWIW, I find that putting these routines in a custom module is much more useful for most purposes than messing around with globals, especially if your needs get at all complex. Anyway, hope this helps.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] Form Names to Form Values In reply to
Thanks hennagaijin + Stone ... that was exactly what we needed.
Quote Reply
Re: [hennagaijin] Form Names to Form Values In reply to
Curiously, this does not work in all circumstances ...

In search_results.html, it does exactly what we expect.

In add_success.html and modify_success.html, it fails -- multiselect columns are not displayed at all

eg: <%Dbsql::Custom::display('country')%> is blank after adding or modifying a record -- even if we have just added a new country. On subsequent searches, the display is correct.

What could be causing this strange effect?
Quote Reply
Re: [YoYoYoYo] Form Names to Form Values In reply to
Hmm... I'm really not sure. You might try temporarily changing the column type from multiselect to checkbox to see if that makes a difference. I have noticed some weirdnesses with the way DBManSQL handles multiselect fields, which may or may not be related to the problem you're experiencing.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] Form Names to Form Values In reply to
In Reply To:
You might try temporarily changing the column type from multiselect to checkbox to see if that makes a difference.

No difference. The data goes into the database, but is not displayed in the template. This is only add_success and modify_success -- it's as though sub display() does not recognize these templates.

This ...
Code:
foreach ( @selected ) {
$output .= "$hash{$_}<br>" if ( $hash{$_} );
}
apparently picks up nothing.

Which makes me think that ...
Code:
my @selected = split(/\n/, $record->{$col});
is empty.

So maybe ...
Code:
my $col = shift;
has no effect.

What does GT think?
Quote Reply
Re: [YoYoYoYo] Form Names to Form Values In reply to
Hi,

You can create a template global to handle this matter. E.g: the global called 'view_selected':

sub {
my $column = shift;
my $tags = GT::Template->tags;
my $cols = $tags->{home}->{db}->cols;
my $values = $cols->{$column}->{'form_values'};
my $names = $cols->{$column}->{'form_names'};
my $hash = $tags->{values} || $tags->{home}->{hsh};
my %data;
foreach my $i (0..$#$names) { $data{@$names[$i]} = @$values[$i]; }
my @selected = split("\n", $hash->{$column});

my $output;
foreach ( @selected ) { $output .= %data->{$_}.'<br>' if ( %data->{$_} );}
chop $output;
return $output;
}

So now you can use <%view_selected%> to display the selected values in your add_success.html or modify_success.html

Hope that helps.

TheStone.

B.
Quote Reply
Re: [TheStone] Form Names to Form Values In reply to
Hi Stone ... how do we use this?

<%view_selected('country')%> returns a blank
Quote Reply
Re: [YoYoYoYo] Form Names to Form Values In reply to
Just add <%view_selected('colum_name')%> to your add_success.html. Ensure the column_name is a select/multipleselect/radio/checkbox form type.

TheStone.

B.

Last edited by:

TheStone: Feb 20, 2003, 11:20 AM
Quote Reply
Re: [TheStone] Form Names to Form Values In reply to
This is strange ... it works perfectly in add_success.html, but does not work at all in modify_success.html (returns a blank, as above).
Quote Reply
Re: [YoYoYoYo] Form Names to Form Values In reply to
Can you add <%GT::Template::dump%> tag to the modify_success.html and send the results to me in private? I'll have a look.

TheStone.

B.
Quote Reply
Re: [TheStone] Form Names to Form Values In reply to
Has anyone managed to solve this one? We have stopped using DBmanSQL because of it, but it would be nice to pick up the pieces again ...
Quote Reply
Re: [YoYoYoYo] Form Names to Form Values In reply to
Hi,

I've also tried to find a solution for this issue - unfortunately, I haven't been successful Unsure. Does anyone have a workaround?

Many thanks for your time
Oliver
Quote Reply
Re: [olivers] Form Names to Form Values In reply to
I've added <%GT::Template::dump%> to modify_success.html and to add_success.html and compared the outputs. I find the following difference:

$tags->{home}->{hsh} doesn't seem to exist in modify_success.html.

Oliver
Quote Reply
Re: [olivers] Form Names to Form Values In reply to
Is that significant? I haven't looked at the code for ten months. Can't remember anything about it.

GT coders: what does it mean?
Quote Reply
Re: [YoYoYoYo] Form Names to Form Values In reply to
I'd be very glad if GT could provide a solution that works for the modify_success page as well. I think it is important that we can map form names to form values on all result pages -> we need to customize all of them.

Thank you,
Crazyliver
Quote Reply
Re: [olivers] Form Names to Form Values In reply to
First I have to say that I have customized a lot of things in my DBMan SQL installation. The problem described in this thread doesn't allways occur - only for some databases (configurations).

I'm really glad that TheStone has sent me a solution that worked for all configurations on our servers. Replace sub modify_success in Home.pm with the following code:

Code:


sub modify_success {
#----------------------------------------------------------------------
my ($self, $id) = @_;
my $lookup = {};
my $pk = $self->{db}->pk;
foreach (@$pk) { $lookup->{$_} = $self->{cgi}->{$_}; }
my $hsh = $self->{db}->get ($lookup, 'HASH');
return ('modify_success.html', {
header => $self->_language('HEA_MODED'),
msg => $self->_language('MOD_SUCCESSFULLY'),
values => $hsh,
($hsh) ? %$hsh : hsh => 1
});
}


Many thanks to TheStCoolne

Winkliver