Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Select/Enum field in Form + how to create new pages

Quote Reply
Select/Enum field in Form + how to create new pages
Hi,

I'm working my way through creating the directory for www.meowhoo.com and have a couple of quetions:

1. I want to add a "country" column to the add/modify-link form. I have a list of all the countries so I want this to be a closed field where users select from a drop down list.

I added a country column to the links properties. The column has the following attributes - col type: Enum, col index: regular, col values: (a list of all countries, seperated by commas), not null: yes, form display: country, form type: select, form names: (identical list of countries), form values: (identical list of countries).

In the include_form template I added a link that says:

<tr><td
valign="top"><%body_font%>Country: </font></td>
<td> <select class="button" name="Country" value="<%if Country%><%Country%><%endif%>" size="40">
</td></tr>

I did try other variations in the template, but I still can't get it to display a proper drop down list, like the one users get to select their categories from. Unsure

2. On another issue - I want to LSQL to create pages for my FAQ, Advertising, Privacy Statement etc., using the same globals and formats it uses to create the rest of the directory. I can create template called respectively faq.html etc. but how can I get LSQL to build them whenever I do a "build all". I guess I need to go into the nph-page.cgi script, but is there anywhere else I need to make a change at? I want to be able to change the script once and then whenever I'll want to change these pages, just work on their templates (which will have their content) and then run "build all". Hope I'm making myself clear. I can make these as static HTML pages and edit them manually whenever I change the directory's design, but I'd much prefer rely on the globals to create a unified look all over.

Thanks.



If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
In Reply To:
1. I want to add a "country" column to the add/modify-link form. I have a list of all the countries so I want this to be a closed field where users select from a drop down list.

I added a country column to the links properties. The column has the following attributes - col type: Enum, col index: regular, col values: (a list of all countries, seperated by commas), not null: yes, form display: country, form type: select, form names: (identical list of countries), form values: (identical list of countries).

In the include_form template I added a link that says:

<tr><td
valign="top"><%body_font%>Country: </font></td>
<td> <select class="button" name="Country" value="<%if Country%><%Country%><%endif%>" size="40">
</td></tr>

I did try other variations in the template, but I still can't get it to display a proper drop down list, like the one users get to select their categories from. Unsure

2. On another issue - I want to LSQL to create pages for my FAQ, Advertising, Privacy Statement etc., using the same globals and formats it uses to create the rest of the directory. I can create template called respectively faq.html etc. but how can I get LSQL to build them whenever I do a "build all". I guess I need to go into the nph-page.cgi script, but is there anywhere else I need to make a change at? I want to be able to change the script once and then whenever I'll want to change these pages, just work on their templates (which will have their content) and then run "build all". Hope I'm making myself clear. I can make these as static HTML pages and edit them manually whenever I change the directory's design, but I'd much prefer rely on the globals to create a unified look all over.

Thanks.


2. Ivan's (Yogi) pagesbuilder plugin would allow you to do that and as many other types of pages (both static & dynamic) you might need in the future. It's available on the gt plugin server in your admin. It's 50$.
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
Hi,

1. Links SQL does not automatically create the select box for you. You need to make a global variable that does this. See the following post for a solution:
http://www.gossamer-threads.com/...i?post=206587#206587

2. I have developed a plugin (PageBuilder plugin) that allows you do just what you want, namely create (any number of) static pages. You can use all the globa from your template directory. The plugins costs USD 50, and can be downloaded directly from the admin area of your Links SQL installation. See the following thread for the features of the plugin:
http://www.gossamer-threads.com/...rum.cgi?post=209811;


I hope this helps.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
Thanks for the quick reply - I'll check the plug-in later on.

I'm still not sure what to do about the select box...Unsure

Ivan, I read the thread you provided and I see the final code they came up with. I inserted that code in the "template globals" page where it said "new" thus creating a new global called "country", right? The code is:

sub { my $element_name = 'Country'; # set the control's name here
my $default_value = 'xyzty'; # and the default country you'd like to use
my @list = qw(
United States
Internet Based
Afghanistan
Albania
....

rest of the countries

...
Zimbabwe
);
grep { tr,_, ,;0 } @list;
# add your countries here. One per line is ok. my $return = q|<select class=
"Country" name="Country"><option value="">---</option>|; my $tags = shift || {};
my $selected = $tags->{$element_name} || $default_value;
$selected = { map {($_=>1)} ref $selected ? @$selected : $selected };

foreach my $country ( @list ) { my $ischosen = $selected->{$country} ? " selected" : ""; $return .= qq|<option$ischosen>$country</option>|; }

$return .= q|</select>|;

return $return; }




In the "include form.html" template I now have:

<tr><td
valign="top"><%body_font%>Country: </font></td>
<td> <%Country%>>
</td></tr>

and when on the website I get this message where I wanted the select box to be:

Unable to compile 'Country':>



Have no idea what this all means - I'm not a perl programmer... all I know is how to copy and paste (+ minor changes" where I'm told Crazy

Thanks,

Anne

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
You're right, the global in that post is not working.... try this global (called country_select):
Code:
sub {

my $element_name = shift;
my $selected_value = shift;
my $default_value = shift || 'United_States';


my @list = qw(
Afghanistan
Albania
Algeria
American_Samoa
Andorra

..............


Zambia
Zimbabwe

);

my $selected = $selected_value || $default_value;
$selected = { map {($_=>1)} ref $selected ? @$selected : $selected };

my $return = qq|<select name="$element_name"> |;
foreach my $country ( @list ) {
my $ischosen = $selected->{$country} ? ' selected="selected"' : '';
(my $country_nice = $country) =~ s,_, ,g;
$return .= qq|<option value ="$country" $ischosen>$country_nice</option>|;
}

$return .= q|</select>|;

return $return;
}
and use it as

<%country_select('Country',$Country,'France')%>

The first argument is the name of the select box, the second is there to display what is already selected, and the third can be used to set a default value (if nothing is selected).

Hope this works better...

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
Thanks!!!! I think it works properly now!! yipee!!! Cool

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
ok .... Unsure

It looked as if it was working properly, but now as I'm trying out the form I get -

Please completely fill out the form below, and we'll add your link as soon as possible

UnsureUnsureUnsure

I'm not a 100% sure it's those fields (I added a select_state global as well). I am trying to change the form and see where's the problem. So far it's happening even when I don't have the country and state on the form (but their still "not null" on the database).


Any ideas what I should do?

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com

Last edited by:

Anat: Aug 16, 2002, 2:25 PM
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
Just to add - I managed to add a new link from the admin interface and I even managed to change the owner so it's not the admin anymore.

I've also managed to add a link as a user if I take out the state and country fields from the form as well as set them as not null: no.
If they're set to "not null: yes" it won't accept the form from a user (only from the admin interface).

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com

Last edited by:

Anat: Aug 16, 2002, 3:17 PM
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
What is the code you have in the templates for entering the Country and State?

Is anything entered into the database when you set "not null" to no?

Maybe you not use an "ENUM" type column, but just a "CHAR", just a thought.

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Aug 17, 2002, 12:58 AM
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
Code in the form:

<tr><td valign="top"><%body_font%>State: </font></td>
<td> <%state_select('State',$State,'Alabama')%>
</td></tr>

<tr><td valign="top"><%body_font%>Country: </font></td>
<td> <%country_select('Country',$Country,'United_States')%>
</td></tr>

They are ENUM and the full list of possible values seperated by line breaks appear in column values, form names and form values (as well as in the global)

I'm not sure about your second question "Is anything entered into the database when you set "not null" to no? " do you mean by the user or by LSQL? I've tried as the user to submit the form with entering something - it's a select box so there's always some option selected.

By the way - I do want this to be a mandatory field so "Not Null" should eventually be set to "yes"

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
What happens when a user tries to submit a link and

a) the country field is set to "not null"
b) the country field is not set to "not null"?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
either way, user gets the message:

Please completely fill out the form below, and we'll add your link as soon as possible.

(just checked again in both mods + deleted the state column altogether so as to try and isloate the problem - thanks for walking me though this one by the way Smile)

You're welcome to try it yourself by the way -

http://www.meowhoo.com/cgi-bin/links/add.cgi

it's set to not "not null" right now

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com

Last edited by:

Anat: Aug 17, 2002, 3:55 AM
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
Did you remove the error tag from the form?

I.e. is there a place where is says (approximately):

<%if error%> <%error%> <%endif%>

If not, could you put it in (it should tell you what the error is...)

EDIT: Also make sure there is a hidden input field

<input type="hidden" name="add" value="1" />

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Aug 17, 2002, 4:05 AM
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
ok - added those tags and now it gives me the following error message:

Country can not contain the value 'United_States'

(or any other country name that I choose).

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
I use the same code with an CHAR field (instead of an ENUM field) and it seems to work. I know that the ENUM uses less storage space, but could you try making it a CHAR field?

BTW I found a bug in my code: the countries are stored with the underscores, but it makes more sense to store the normal country names. The code below is the updated global:
Code:
sub {
my $element_name = shift;
my $selected_value = shift;
my $default_value = shift || 'United States';

my @list = qw(
Afghanistan
Albania
Algeria
American_Samoa
......................
Zimbabwe
);

my $selected = $selected_value || $default_value;
$selected = { map {($_=>1)} ref $selected ? @$selected : $selected };

my $return = qq|<select name="$element_name"> |;
foreach my $country ( @list ) {
(my $country_nice = $country) =~ s,_, ,g;
my $ischosen = $selected->{$country_nice} ? ' selected="selected"' : '';
$return .= qq|<option value ="$country_nice" $ischosen>$country_nice</option>|;
}

$return .= q|</select>|;

return $return;
}

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
Ivan, the new code you just provided American_Samoa still has underscores. So should I keep the underscores or not?

I'll try the CHAR option in a minute and let you know. What's the difference in storage?

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
You should leave the underscores in the countries that are in the list, it will automatically remove them. The underscores have to be there in the list in order for the program to know what belongs together....

The difference in storage is (I think) that with ENUM, the database just stores a number (that corresponds to the entry), and with CHAR it actually stores the string.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
It was working... so I added the same thing for State - added a similar global called "state_select" and a state column.

It looks alright on the form and the user gets the proper confirmation message with the country and state listed properly on it... however, when I go to validate the link in the admin panel, I can't see the country the user had selected - only the state Crazy For that reason it won't let me validate the listing (as both state and country are set to "not null")

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
So the state is working, but not the country? Strange.... Have you set both to CHAR?

BTW: I noticed that your list of states has a problem with New York etc, it lists New and York on separate lines. I think you probably forgot to use the underscores in the list.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
Yes, both set to CHAR(50), not null, column index: regular

Here are the two globals again - maybe you can see something I don't?


country_select

sub {
my $element_name = shift;
my $selected_value = shift;
my $default_value = shift || 'United_States';

my @list = qw(
United_States
Internet_Based
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua_and_Barbuda
....

Vietnam
Western_Sahara
Yemen
Yugoslavia_(Serbia_and_Montenegro)
Zambia
Zimbabwe

);
my $selected = $selected_value || $default_value;
$selected = { map {($_=>1)} ref $selected ? @$selected : $selected };

my $return = qq|<select name="$element_name"> |;
foreach my $country ( @list ) {
(my $country_nice = $country) =~ s,_, ,g;
my $ischosen = $selected->{$country_nice} ? ' selected="selected"' : '';
$return .= qq|<option value ="$country_nice" $ischosen>$country_nice</option>|;
}
$return .= q|</select>|; return $return;
}





state_select

sub {
my $element_name = shift;
my $selected_value = shift;
my $default_value = shift || 'Alabama';

my @list = qw(
Alabama
Alaska
Arizona
Arkansas
....
Virginia
Washington
West_Virginia
Wisconsin
Wyoming
Outside_the_USA


);
my $selected = $selected_value || $default_value;
$selected = { map {($_=>1)} ref $selected ? @$selected : $selected };

my $return = qq|<select name="$element_name"> |;
foreach my $state ( @list ) {
(my $state_nice = $state) =~ s,_, ,g;
my $ischosen = $selected->{$state_nice} ? ' selected="selected"' : '';
$return .= qq|<option value ="$state_nice" $ischosen>$state_nice</option>|;
}
$return .= q|</select>|; return $return;
}





If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
Hmm, I don't see anything that could cause the problems....

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
I keep trying this and the way I see it, country never makes it past the "add_success" screen to the admin panel. State does so only if the name of the state is one word and not two.

Maybe that might help someone solve the mystery? Pirate




User feeds: New York, Andorra

Admin panel validation page shows: no state, no country




user feeds: New York, United States

Admin panel validation page shows: no state, no country




user feeds: Alabama, Andorra

Admin panel validation page shows: Alaska, no country




user feeds: Alabama, Unites States

Admin panel validation page shows: Alabama, no country




If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
Could it be because it says

<option value ="Alabama">.....

(note the space between value and =....

?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
sorry, you lost me there Unsure where does it say <option value ="Alabama">?

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
In your global, it says somewhere,

<option value ="$state_nice"

This should certainly be

<option value="$state_nice"

(i.e. no space). But I don't know if that is the cause.

BTW: I just submitted a link to your site, and it gave the correct state and country on the confirmation page.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
I can see your link. Country is not shown and state shows as Alabama. I know the confirmtaion page works just fine. Only when it gets to the admin panel the info is lost. As admin I will not be able to know what the user selected as country :(

I will try and fix the globals and see what happens.

Thanks for all your help!

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
Have you set the fields to CHAR? What size do they have? The fact that the confirmation page is fine, but the admin does not get the correct values, points to a mistake in the database. Have you double checked the names of the database fields?

It's just so strange, because I use exactly the same code, and it works for me.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Select/Enum field in Form + how to create new pages In reply to
Just so everyone knows - Ivan found out what the problem was! Apparently the values in the column had a few spaces after each one. Once the spaces were cleared everything worked just fine.

Thank you Ivan!

If you love cats - visit www.TheCatSite.com

Visit my LinkSQL based Cat Site - www.Meowhoo.com
Quote Reply
Re: [Anat] Select/Enum field in Form + how to create new pages In reply to
The select field fails to updates when u modify the link and the field. It just maintains the initial value even after the modification! Can you help, Ivan?