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

How to use build_select_field

Quote Reply
How to use build_select_field
How to use a select form field?
I have a Links field called 'Area' in SQL.pl as follows:

Area ENUM ('America', 'Europe', 'Asia') NOT NULL,

I added the following in %globals in HTML_Templates.pm

Area => \&Links: BSQL::build_select_field ("Area", "$in{'Area'}"),

But it didn't work.
How to correct this? Thank you.

Quote Reply
Re: How to use build_select_field In reply to
It should automatically create a select field for you. Is Area a new field in the Links table? If so, edit Links.def and add:

Area => 'America,Europe,Asia'

to the build_select_fields list.

Cheers,

Alex
Quote Reply
Re: How to use build_select_field In reply to
It did automatically create a select field in Links.def.
When I try to add Links in the admin menu, there is no problem. It shows a select form in the field--Area .

My problem is when I click on Add a Site (add.cgi), it shows error:
Software error:
HTML_Templates.pm: Compilation failed in require at add.cgi line 35. BEGIN failed--compilation aborted at add.cgi line 35.

line 35 is: use Links::HTML_Templates;

I think there is a syntax error in:
Area => \&Links: BSQL::build_select_field ("Area", "$in{'Area'}"),

I can't figure it out.

Quote Reply
Re: How to use build_select_field In reply to
What error is your error.log reporting? That usually will give you a good idea of what is causing the problem.

Quote Reply
Re: How to use build_select_field In reply to
There is no error reporting in error.log.
When I run add.cgi from telnet, it shows:
HTML_Templates.pm: Global symbol "in" requires explicit package name at admin/Links/HTML_Templates.pm line 55.

line 54: my %globals = (
line 55: Area => \&Links: BSQL::build_select_field ("Area", $in{'Area'}"),
line 56: date => \&Links: BSQL::get_date,
Quote Reply
Re: How to use build_select_field In reply to
You can now do the same thing using templates:

<select name="Area">
<option value="America"<%if Area eq 'America'%> SELECTED<%endif%>>America
<option value="Europe"<%if Area eq 'Europe'%> SELECTED<%endif%>>Europe
<option value="Asia"<%if Area eq 'Asia'%> SELECTED<%endif%>>Asia
</select>

Should work. Otherwise, you need to add:

$tags->{Area} = $db->build_select_field ('Area', $tags->{Area});

to whichever subroutine you want the select list in.

Hope this helps,

Alex
Quote Reply
Re: How to use build_select_field In reply to
Hello Alex!

Does this mean that I can have a category selection from the forms as well?

------------------
rajani











Quote Reply
Re: How to use build_select_field In reply to
Hello, Alex. Thank you.
1. The first method works.
2. The second method--Where to add the following line?
$tags->{Area} = $db->build_select_field ('Area', $tags->{Area});

I tried to add it in sub site_html_add_form before:
print &load_template ('add.html', {

But it gave me an error:
HTML_Templates.pm: Global symbol "db" requires explicit package name at admin/Links/HTML_Templates.pm line 180.
Quote Reply
Re: How to use build_select_field In reply to
For the second method, you'll need to create a db object. So do something like:

my $db = new Links: BSQL "$LINKS{admin_root_url}/defs/Links.def";
$tags->{Area} = $db->build_select_field ('Area', $tags->{Area});

(the happy face is a : followed by a D).

Just add these two lines before the load_template.

Cheers,

Alex


Quote Reply
Re: How to use build_select_field In reply to
It works. Thanks! Alex!
Quote Reply
Re: How to use build_select_field In reply to
Actually, I made one change to get it to work.
I added these two lines before the load_template:
my $db = new Links: BSQL $LINKS{admin_root_path} . "/defs/Links.def";
$tags->{Area} = $db->build_select_field ('Area', $tags->{Area});

I successfully added a site from add.cgi(a site with the field Area--America). However;when I tried to validate the link I had just added, the field Area was not selected(was blank).
Quote Reply
Re: How to use build_select_field In reply to
This might have something to do with what I just posted, then again, maybe not.

The Validate table needs to look like the Links table, but it doesn't. When a change is made to the Links .def or table, you need to make the corresponding change to the Validate table.

Quote Reply
Re: How to use build_select_field In reply to
Hi, pugdog,
You are right.
Thank you for your point. It solves the problem.
Quote Reply
Re: How to use build_select_field In reply to
 I also made some changes to solve other problems.

1. Added the following 3 lines to Validate TABLE:
isChanged ENUM ('Yes', 'No') NOT NULL DEFAULT 'No',
Status SMALLINT NOT NULL DEFAULT 0,
Date_Checked DATETIME DEFAULT 0,

2. Added the following to $LINKS{add_system_fields} in Links.pm:
Status => 0, isChanged => 'No'

When I added a site from add.cgi, and tried to validate it, the field Date_Checked was set to:1999-10-05 12:51:24.
However; when I modified a site from modify.cgi and tried to validate it,
the field Date_Checked was set to:0000-00-00 00:00:00.

Alex, did I do it right or wrong?

Another problem: Duplicate Check does not work.(admin.cgi?db=Links&view_records=1&URL=.....)