Gossamer Forum
Home : Products : Gossamer Links : Discussions :

how do you auto generate the add form

Quote Reply
how do you auto generate the add form
Does anyone know how to auto generate the add form so that it is like the add link form in the admin. I don't want to type out all the form fields that will be needed to add a link and since in the admin the form is displayed automatically i think i shouldn't have to.

Please help. thanks
Quote Reply
Re: [vanhut] how do you auto generate the add form In reply to
It's not straightforward, but could in principle be done using the GT::SQL::Admin module.

However, this module is meant for administrators, not website users. In particular, it will automatically generate a link to "Properties" at the bottom of the page, which allows you to change the properties of your table (adding/deleting fields etc). So it is not a good idea to use it for people adding links.

So basically you will have to type out your form fields...

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] how do you auto generate the add form In reply to
is there a way i can access the links.def file and get the posible values of a field. this would be helpful.
Quote Reply
Re: [vanhut] how do you auto generate the add form In reply to
You can access it via:
Code:
my $values = $DB->table('Links')->cols->{'Column Name'}->{form_values};
($values result is an array reference of the form values you have)

I hope this is what you need.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [vanhut] how do you auto generate the add form In reply to
I've been doing it sucessfully using this global I called getform (don't call it form as that will cause problems)

This works for adding and modifying links. You still need to use the <%Category%> tag

Replace include include_form.html with <%getform%> and add the following as a global.

You'll probably want to make some custom changes to the hide and skip vars. You can discover more options by looking in GT::SQL::Display::HTML.pm

I don't remember if my $category_info is necessary or not.

Here's the global:

sub {
my $rec = shift;
my $link_id = $rec->{'LinkID'};
my $category_id = $rec->{'CatLinks.CategoryID'} || $rec->{'ID'};
my $category = $DB->table ('Category');
my $links = $DB->table ('Links');
my $category_info = $category->get ( { ID => $category_id }, 'HASH', ['ID', ,'Full_Name','Name', 'Number_of_Links'] );
my $link_info = $links->get ( { ID => $link_id } );
my $record;
my $error = $rec->{'error'};
my $script;

if (($link_id) and (!$error)) {
$record = $link_info;
} else {
$record = $rec;
}

if ($ENV{'SCRIPT_NAME'} =~ m/add.cgi/){
$record->{ID} = "";
}
my ($file_field,$file_delete, $skip);
if (($rec->{Status} eq "Editor") or ($rec->{Status} eq "Administrator")) {
$file_field = '1';
$file_delete = '1';
$skip = [qw/CatLinks.LinkID Timestmp/];
} else {
$file_field = '0';
$file_delete = '0';
$skip = [qw/Thumbnail Detail CatLinks.LinkID Timestmp Reviews_Allowed/];
}

my $hide;
$hide = [qw/ID isValidated isNew isChanged isPopular Status Date_Checked Timestmp Hits Rating Votes Add_Date Mod_Date LinkOwner /];


my $h = new GT::SQL::Display::HTML::Table ( { db => $links, input => $record } );
return form => $h->form ( { defaults => 1, file_field => $file_field, file_delete => $file_delete, hide_downloads=>1, skip => $skip,
hide => $hide, table => qw/width=640 border=1/
});
}

Hope it works for you.

peace.
klangan
Quote Reply
Re: [klangan] how do you auto generate the add form In reply to
Klangan:

that is what i was looking for. I however i have another situation where i want to be able to format it a bit differently. what i have in the for, among other things, is a list of about 70 checkboxes. i want to beable to format them with a table so it looks much neater. i also want to beable to get the boxes the user had checked so that i can recheck the boxes on the modify form.

Also i was trying to use the
my $values = $DB->table('Links')->cols->{'col name'}->{form_values};

to out put the different possible values but i couldn't get it to work. It just printed out my sub function and not any values. is there a display function i need to use to get the sub to display right.

Is there a list of functions that or info for developers?
Quote Reply
Re: [vanhut] how do you auto generate the add form In reply to
HI Vanhut,

You'll have to edit GT:SQL::HTML.pm sub checkbox {

Note that whatever changes you make to that subroutine will appear in the editor section and the admin section.

I hope GT comes up with some formatting options for properties->field. I'd like to see more options available for textareas that allows us to specify wrapping, checkboxes and radio buttons could allow us to specify columns.

I agree and have implemented building checkboxes into 3 or 4 columns within a table using that sub, but it's a static change and I hate making those kinds of changes as it makes upgrading problematic and I have no desire to assume responsibility for sites I don't work directly on.

Anyway, with all that said, here's the mod, you'll need to find the proper location (and yes, it's based on GT code found elsewhere):



# Figure out how to order this select list.
my @keys;
if ($sort_o) { @keys = @$sort_o; }
elsif ($sort_f) { @keys = sort { $sort_f->() } keys %hash }
else { @keys = keys %hash }

if (! ref $def) {
$def = [sort split (/\Q$INPUT_SEPARATOR\E%?/o, $def)];
}
# klangan mod returns checkbox list in equal columns
$out .= qq|<table width=100%><tr valign=top><td><font $self->{font}>|;
my $i = 0;
my $columns = "3";
my $counter = "0";
my $width = int (100 / $columns);
my $number= scalar @keys;
my $breakpoint = int (($number) / $columns) + ( (($number) % $columns) ? 1 : 0);
# klangan mod
KEY: foreach my $key (@keys) {
# klangan mod
if ($number > '4') {
($i > 0) and !($i % $breakpoint) and ($out .= qq|</td>\n<td valign="top"><font $self->{font}>\n|);
$i++;
}
# klangan mod
my $val = $hash{$key};
_escape(\$val);
VAL: foreach my $sel (@$def) {
($key eq $sel) and ($out .= qq~ <input name="$name" type="checkbox" value="$key" checked>$val<br>~) and next KEY;
}
$out .= qq~ <input name="$name" type="checkbox" value="$key">$val<br>~;
}
# klangan mod
$out .= "</td></tr></table>";
# klangan mod




peace.

klangan