Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Auto Generate Form Fields

(Page 1 of 4)
> >
Quote Reply
Auto Generate Form Fields
I'm sure this is either obvious or has been discused before but I can't find it in with a search....

I'd like to automatically generate some drop-downs and checkbox fields from the database and call then with <%tags%> on the add.html template. How do I do this?

Safe swoops
Sangiro
http://www.dropzone.com/
Quote Reply
Re: Auto Generate Form Fields In reply to
Alex should answer this, so we have the right way.

It would most likely involve creating a sub {} in the globals.txt file, but I know he has added the tools to do lists more easily.

Too much for me to try to figure out all at once. It's going to take me awhile to catch up with the 2.0 version <sigh>.... so much going on!

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


Quote Reply
Re: Auto Generate Form Fields In reply to
Hi,

Pugdog has got the right idea. Go to Build->Template Globals and add a tag called 'dropdown' and put:

Code:
sub {
my $links_db = $DB->table ('Links');
my $sth = $links_db->select ( ['CustomField'] );
my @vals;
while (my $field = $sth->fetchrow) { push @vals, $field; }
my $html = $DB->html ($links_db, $IN);
my $select = $html->select ( name => 'CustomField', values => \@vals );
return $select;
}
What this does is line by line:

1. Get a GT::SQL::Table object for the Links table.
2. Select the CustomField values from the Links table.
3. Go through the results and save them in @vals.
4. Get a GT::SQL::Display::HTML object to display forms.
5. Generate a select list with name='CustomField' using the values we just generated.
6. Returns the select list.

You can simliarily use ->checkbox, or ->radio instead of select to generate different values.

Hope this helps,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Auto Generate Form Fields In reply to
Hey Alex,

Tried to build a radio select field (simple yes/no select) from the database using your code:

In Reply To:
sub {
my $links_db = $DB->table ('Links');
my $sth = $links_db->select ( ['Tandem'] );
my @vals;
while (my $field = $sth->fetchrow) { push @vals, $field; }
my $html = $DB->html ($links_db, $IN);
my $radio = $html->radio ( name => 'Tandem', values => \@vals );
return $radio;
}
This gave me the following error:

In Reply To:
Error in subroutine: Can't use string ("name") as a HASH ref while "strict refs" in use at /path_to_script/admin/GT/SQL/Display/HTML.pm line 284.
Suggestions?

Safe swoops
Sangiro
http://www.dropzone.com/
Quote Reply
Re: Auto Generate Form Fields In reply to
I got the same error message. What's may possibly wrong?

Thanks

http://www.biomedgate.com
****Portal to life****
Quote Reply
Re: Auto Generate Form Fields In reply to
Alex...any thoughts on this error?

Safe swoops
Sangiro
http://www.dropzone.com/
Quote Reply
Re: Auto Generate Form Fields In reply to
Hi,

Sorry, I may be not understanding what you are trying to do. Are you trying to generate a select/radio list with the values being all the values in the database? Or are you trying to generate a select/radio list with the values being the allowed values for that field?

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Auto Generate Form Fields In reply to
Alex,

Not exactly sure what the difference is in your mind but I believe I'm trying to do the latter. i.e. When you create a new column in the database, you can enter a range of possible options for that field (let's assume it's select field)

When using the admin interface to add a link that select field will be built automatically with all the possible options to choose from. I'd like to do the same and imbed it in the add.html template through a tag.

I'd be interested in knowing how to do te first one as well! That would open all kinds of interesting possibilities!

Safe swoops
Sangiro
http://www.dropzone.com/
Quote Reply
Re: Auto Generate Form Fields In reply to
In Reply To:
trying to generate a select/radio list with the values being the allowed values for that field?
That will be my interested, and if possible, those allowed values could be import from a text file or database fields.



Quote Reply
Re: Auto Generate Form Fields In reply to
Alex,

Any help on this?

Safe swoops
Sangiro
http://www.dropzone.com/
Quote Reply
Re: Auto Generate Form Fields In reply to
I like also to have the auto-generatet dropdown/select fields on the add.html like it is at add-function of the admin section.

Michael

Quote Reply
Re: Auto Generate Form Fields In reply to
So let's assume we are dealign with the Status field in the User table which has values 'Not Validated', .., 'Administrator'. We want to build a select list out of this now. I think this would be the quickest way:

Code:
sub {
my $html = $DB->html ( ['Users'], $IN );
return $html->select ( { name => 'Status', value => 'Default' });
}
Default is the value you want to Default it to. If you don't specify it, I think it will use CGI input instead.

Hope this helps,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Auto Generate Form Fields In reply to
Alex,

it builds a select field, but in my case it contains no data to select, like it does in admin section.

Michael

Quote Reply
Re: Auto Generate Form Fields In reply to
Same problem here. Builds an empty select field.

Safe swoops
Sangiro
http://www.dropzone.com/
Quote Reply
Re: Auto Generate Form Fields In reply to
in the links.def file are my options under form_values,
like i made the input at links-properties.
the values section is empty.

'values' => [
],

Michael

Quote Reply
Re: Auto Generate Form Fields In reply to
Alex,

did you fix this in 2.02 ??

I still get empty select-fields.

Michael

Quote Reply
Re: Auto Generate Form Fields In reply to
Hey Alex,

Looking at the amount of times this thread has been viewed by comparison to others, it seems like there are a lot of folks who are curious about how this is done. Any additional thoughts?

Safe swoops
Sangiro
http://www.dropzone.com/
Quote Reply
Re: Auto Generate Form Fields In reply to
Hi,

I'll figure this one out when I get back on tuesday. =)

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Auto Generate Form Fields In reply to
Hi Alex,

Did you already figure this one out?



Quote Reply
Re: Auto Generate Form Fields In reply to
Hi,

This is a bug in the html module and will be fixed in the next release due out shortly.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Auto Generate Form Fields In reply to
I updated to 2.0.3

Now, if I add a new Column (select field) then in the admin there is shown a
multiselect field !?

Whats wrong? And what is exactly to do to display the field in the add.cgi form?

Quote Reply
Re: Auto Generate Form Fields In reply to
Hi,

The form_size attribute determines how many you can select, make sure it is at 0 to make it a single select.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Auto Generate Form Fields In reply to
Thanks Alex that is OK (in the admin, it works),
but what is now exactly to do to display the select field in the add.cgi formular?
I tried it with the globals as you decscibe it above but this doesnt work it only
shows an "Unknown Tag:" message.

Quote Reply
Re: Auto Generate Form Fields In reply to
Hi,

The code at http://gossamer-threads.com/p/127748 works fine for me. Are you sure you are putting it in the right template set?

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Auto Generate Form Fields In reply to
Hi Alex,

Ok all works fine - I added my select tag in the add formular - great - but if a user dont fill out all the fields
the add-error template resets all the select fields and the user has to fill out all select fields again.
How can I take the input values of the select and radio fields in the add error formular? I think little changes in global templates can help?

> >