Gossamer Forum
Home : Products : Links 2.0 : Customization :

Multiple Categories Mod v2 - How to add it to user forms?-Template Users

(Page 1 of 2)
> >
Quote Reply
Multiple Categories Mod v2 - How to add it to user forms?-Template Users
Thanks Bogus for the pointer to your site to give me a lead on how to add it to the user add form. And a special thanks to Loopy who laid out the ground work.

******************************************
I do need assistance on formatting. The result page is in need of some parsing. If more than one alt category is chosen, the format is as follows:

Code:
exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value);

with this:

Code:
exists $in{$name} ? ($in{$name} .= "<br>$value") : ($in{$name} = $value);
**************************************

This is what needs to be modified if you want to add it to the user add/modify form:

Before we continue, go to www.online-sweepstakes.com/links-mods/ to add the mod. Then continue:

1. db_utils.pl

add this:
Code:
if (! exists $db_select_fields{$column} && $column eq "AltCategories" && exists $db_select_fields{'Category'}) {
$db_select_fields{$db_cols[$db_alt_cat]} = $db_select_fields{'Mult-AltCategories'} = $db_select_fields{'Category'}}
elsif (! exists $db_select_fields{$column} && $column eq "AltCategories" && ! exists $db_select_fields{'Category'}) {
$db_select_fields{$db_cols[$db_alt_cat]} = $db_select_fields{'Mult-AltCategories'} = join (",", &category_list);}

after this in sub build_select_field:

Code:
if (! exists $db_select_fields{$column}) {
$db_select_fields{$db_cols[$db_category]} = $db_select_fields{'Mult-Related'} = join (",", &category_list);
}

2. site_html_templates.pl

here is what my add/modify section looks like:

Code:
########################################################################################
# THE FOLLOWING ARE CGI GENERATED PAGES AND THE TEMPLATE MUST BE PRINTED, NOT RETURNED!#
########################################################################################

sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#
&html_print_headers;

my $category = shift;
# $category ?
# ($category = qq~$category <input type=hidden name="Category" value="$category">~) :
# ($category = &build_select_field ("Category", "$in{'Category'}"));
my $category = &build_select_field ("Category", "$category");
my $altcategories = &build_select_field ("AltCategories","$in{'AltCategories'}","AltCategories","MULTIPLE Size=3");

print &load_template ('add.html', {
AltCategories => $altcategories,
Category => $category,
%globals
});
}

sub site_html_add_success {
# --------------------------------------------------------
# This routine determines how the add success page will look like.

&html_print_headers;

print &load_template ('add_success.html', {
AltCategories => $altcategories,
%in,
%globals
});
}

sub site_html_add_failure {
# --------------------------------------------------------
# This routine determines how the add failure page will look like.

my ($errormsg) = shift;
my $category = &build_select_field ("Category", "$in{'Category'}");
delete $in{'Category'};
my $altcategories = &build_select_field ("AltCategories","$in{'AltCategories'}","AltCategories","MULTIPLE Size=3");
delete $in{'AltCategories'};

&html_print_headers;
print &load_template ('add_error.html', {
AltCategories => $altcategories,
Category => $category,
error => $errormsg,
%in,
%globals
});

}

sub site_html_modify_form {
# --------------------------------------------------------
# This routine determines how the modify form page will look like.

my $category = &build_select_field ("Category", "$in{'Category'}");
my $altcategories = &build_select_field ("AltCategories","$in{'AltCategories'}","AltCategories","MULTIPLE Size=3");


&html_print_headers;
print &load_template ('modify.html', {
AltCategories => $altcategories,
Category => $category,
%globals
});
}

sub site_html_modify_success {
# --------------------------------------------------------
# This routine determines how the modify success page will look like.

&html_print_headers;
print &load_template ('modify_success.html', {
AltCategories => $altcategories,
%in,
%globals
});
}

sub site_html_modify_failure {
# --------------------------------------------------------
# This routine determines how the modify failure page will look like.

my $errormsg = shift;
my $category = &build_select_field ("Category", "$in{'Category'}");
delete $in{'Category'};
# $in{'Category'} = &build_select_field ("Category", $in{'Category'});
my $altcategories = &build_select_field ("AltCategories","$in{'AltCategories'}","AltCategories","MULTIPLE Size=3");
delete $in{'AltCategories'};

&html_print_headers;
print &load_template ('modify_error.html', {
AltCategories => $altcategories,
Category => $category,
error => $errormsg,
%in,
%globals
});
}

3. add.html,add_error.html,add_success.html,modify.html,modify_error.html,and modify_success.html

add this to the user form in between any field you want:

Code:
<tr>
<td align="right" valign="top">Alt Categories:</td>
<td><%AltCategories%></td>
</tr>

4. add.cgi and modify.cgi

add this at sub send_email:
Code:
Alt Categories: $in{'AltCategories'}

That should be it...

The only thing that really needs fixing is how it displays the success page on more than one alt categories.

Hope this addition is useful to all of you Smile

Best wishes,
elms

------------------
www.webmerch.com
links@webmerch.com

[This message has been edited by elms (edited March 19, 1999).]
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Elms,
I followed everything here on the page at forums at gossemer threads and everything works great! Exept it won't save the additional categories to the database. Any ideas.

------------------
Joker
Concepts 2000 Online
www.concepts2000.com
tech@concepts2000.com

Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Make sure that links.db is updated to handle the extra field. Check to see if it is being added to validate.db and see also if you can add alt categories through the admin panel. I have a feeling that you may need to go over loopy's set of instructions for adding alt categories again to check for syntax.

Let me know how it works out and what it is doing.

elms
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Didn't do anything yet, seems to be working fine now. Just had a user add to multiple catagories with no problems. Thanks!

------------------
Joker
Concepts 2000 Online
www.concepts2000.com
tech@concepts2000.com

Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Can't figure it out..for some reason I can't build the alt categories properly!
I am using templates btw...

One thing I did do different than the instructions is I put the extra field "altcategories" at the end of the list of fields instead of directly after category....I don't see why that should matter but perhaps there is a reason? Any ideas?

Thanks.

------------------
http://www.diamondgrading.com
Learn about Diamonds from former Gem-Lab Graders
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
wait a sec.. the ~~ is actually "|" parsed for the db so it would look like a field.. i'm guessing you are only doing this so it will display on the success page?

cause right now.. it already adds to multiple categories properly..

jerry
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Hi Widgetz,
I got a little confused by what you wrote, but then I realized...I guess you were answering the original post?

I wonder if someone can help me...I'm real confused why the alt categories are not being created. I went through EVERYTHING....Thanks.
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Hi,
Has anyone done this without templates? Please help! Thanks.
Greetings,
Gerrit
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Never mind... got it figured out, and also got the bugs out of it... took only 4 hours... at least it seems to work without problems now Smile
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Did anyone figure out how to get the success results page to display alt categories with breaks <br>? The above:

exists $in{$name} ? ($in{$name} .= "<br>$value") : ($in{$name} = $value);

does not work. It simply separates the alt categories with <BR> in the validate.db.

Regards,

Zaro
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
I just answered you other Topic, zaro!!!

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Hi Eliot,

Not sure what difference does REM that line of code and simply replacing ~~ with <BR>. Anyhow, I have an more important problem. I'm trying to use templates with the add_error.html, add_confirm.html, and add_success.html. I have tried several ways including:

if ($category_name =~ "Computers") {
$template = "computers_error.html"; }
else { $template = "add_error.html"; }
print &load_template ( $template, {

Also added the:

my $template;

it will not use the template computers_error.html and defaults to add_error.html. I have also tried:

$in{'Category'}
$rec{'Category'}

but nothing seems to work. I think the:

print &load_template ( $template, {

has something to do with it since the others use:

return &load_template ( $template, {

Anyone know how to get templates woking with the add_error.html, add_confirm.html, and add_success.html?

Regards,

Zaro
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Well, that is your problem....You are using completely wrong codes for creating the AltCategories List in your add forms. Look at the steps in the first Post.

Also, using multiple templates like you are doing is not the direction you want to go, I think.

What is your ultimate goal? What do you want to appear in the add forms? Be specific and we may be able to assist you.

I am still unsure what you are trying to do.

Regards,


------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Hi Eliot,

This is what I am trying to do:

1) Say an user adds an entry and selects the "Computers" category (lets forget about AltCategories).

2) By default, the user will get the standard add.html, modify.html, confirm.html and error.html regardless of the category he/she selects.

3) Now, what if we wanted the user to get category_specific add.html, modify.html, confirm.html and error files.

4) The benefit of using category_specific templates is that specific "Category" instuctions, errors and confirmations can be built into Links.

Hope this explains what I am trying to do. One would think that the multiple template code would work, but it does not. I assume this is because of the "print" command as oppose to "return" -- but it could also be due to the fact that nph-build.cgi is not being used. If anyone has any suggestions I would sure like to hear them.

Best regards,

Zaro
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Well, the problem is that $category_name is not defined in add.cgi and cannot be used. Also, there is no way to pull the category name in the manner that you've written it.

Try adding the following codes:

Code:
my $category = shift;
my $clean_category = &build_clean($category);
if ($clean_category eq "Computers") {
$template = "computer_error.html";
}
else {
$template = "add_error.html";
}

I don't gaurantee these codes will work, but these codes are more logical than the ones you've tried.

Regards,





------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
 
Quote:
As you can see $category_name was not defined but $category was ... anyway, the same code above can be used for custom category_specific add.html, modify.html, confirm.html and error files.

DUH...That is what I stated in my Reply, and I said that there was no gaurantee, and I did state that $category_clean is not defined.

Good luck with your LINKS project!

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Hi Eliot,

Your code did not work but it gave me an idea (I feel a little stupid today knowing the solution was in front of my nose -- guess that what you get when trying to do something when your tire:-).

Solution:

Add this to the sub site_html_add_failure routine in the site_html_templates.pl file.
my $category = &build_select_field ("Category", "$in{'Category'}");
if ($category =~ "Computers") {
$template = "computers_error.html"; }
else { $template = "add_error.html"; }

&html_print_headers;
print &load_template ($template, {

As you can see $category_name was not defined but $category was ... anyway, the same code above can be used for custom category_specific add.html, modify.html, confirm.html and error files.

Regards,

Zaro


[This message has been edited by zaro (edited March 18, 2000).]
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Ok Eliot ...

I did this ... but when I change ~~ for <br>
my altcategories don't save into the validate
this is the problem.

Do you known how can I solve this problem ???

Regards,

Marco Aurélio
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Marco,

That is all you have to do.

Delete the first set of codes, and then REPLACE or PASTE the second of codes!

Pretty straightforward, if you ask me.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Hi Eliot !!!

I visited your site and repaired that your altcat works perfectly and display it whith a <br> tag. How did you get this ??? because I tried to make this (look below) but don't work.

replace this in db_utils:


code:
--------------------------------------------------------------------------------

exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value);

--------------------------------------------------------------------------------

with this:


code:
--------------------------------------------------------------------------------

exists $in{$name} ? ($in{$name} .= "<br>$value") : ($in{$name} = $value);


Please, help me whith this problem !


Best Regards,

Marco Aurélio
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Well ...

I make this in db_utils.pl:

code:
--------------------------------------------------------------------------------

$tmp =~ s/\Q$db_delim\E/~~/og; # Change delimeter to ~~ symbol.

raplace whith ->

code:
--------------------------------------------------------------------------------

$tmp =~ s/\Q$db_delim\E/<br>/og; # Change delimeter to ~~ symbol.

and ...

code:
--------------------------------------------------------------------------------

s/~~/$db_delim/g; # Retrieve Delimiter..

replace whith ->

code:
--------------------------------------------------------------------------------

s/<br>/$db_delim/g; # Retrieve Delimiter..


please tell me if this can cause me any problems ...

Regards,


Marco Aurélio
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Again...you delete the following codes:

Code:
exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value);

And then add the following codes:

Code:
exists $in{$name} ? ($in{$name} .= "<br>$value") : ($in{$name} = $value);

Best of luck!

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Great Eliot !!!

Now my altcat works properly and my add_success page is ok whith <br> tags in altcat list, but I had make this changes for this ...

My code in db_utils:

code:
--------------------------------------------------------------------------------

sub join_encode {
# --------------------------------------------------------
# Takes a hash (ususally from the form input) and builds one
# line to output into the database. It changes all occurrences
# of the database delimeter to '~~' and all newline chars to '``'.

$tmp =~ s/\Q$db_delim\E/<br>/og; # Change delimeter to ~~ symbol.

--------------------------------------------------------------------------------

code:
--------------------------------------------------------------------------------

sub split_decode {
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.
s/<br>/$db_delim/g; # Retrieve Delimiter..

--------------------------------------------------------------------------------

code:
--------------------------------------------------------------------------------

exists $in{$name} ? ($in{$name} .= "<br>$value") : ($in{$name} = $value);

--------------------------------------------------------------------------------


Where I found ~~ symbol, I changed it for <br> !!!

I did make any tests and aparently all is works perfectly.

Now I only want know if this can cause any problem to my database.

Thanks one more time,

Marco Aurélio
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Yes...you have made too many changes. All I said was delete one line of code and add another. The codes you have changed will now put <br> codes in your AltCategories field in your admin.cgi script.

Did you test your admin.cgi?

Wink

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Multiple Categories Mod v2 - How to add it to user forms?-Template Users In reply to
Ok Eliot

Yes I did. My admin.cgi displays this in the altcat field:

AltCategories: Matérias-Primas/Indústrias|Matérias-Primas/Indústrias/MDF|Matérias-Primas/Lojas

I think that all is working correctly !!!

What do you think ??? Any suggestion ???

Marco Aurélio
> >