Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Help needed with different form for different category

Quote Reply
Help needed with different form for different category
Hi, I am sure this can be done but I'm not experienced enough to know where to start.

Basically what I'm trying to do is on the include_form template. What I want is to display a different form depending on the category someone is adding into.

I have links set so that the user has to be in the specific category before placing an ad but what I want to do is tell links that if the category equals say 'business' to show one version of the include form but if it's any other category to show something else.

The thing is I have a lot of subcategories and I've tried <%if FatherID == X%> followed by the html and then an endif statement, followed by the alternative html but it only ever comes up with the alternative html not the one for that specific category.

Any help from anyone would be greatly appreciated

Many thanks

Sal
Quote Reply
Re: [Sal2] Help needed with different form for different category In reply to
Try something like that in add.html:
<%if ID == 2%><%include include_form2.html%>
<%elsif ID == 8%><%include include_form8.html%>
<%elsif ID == 9%><%include include_form9.html%>
<%else%><%include include_form.html%>
<%endif%>

Note, that I didn't try out, but theoritically should work.

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: [webmaster33] Help needed with different form for different category In reply to
This works:

<%if ID=YOUR ID HERE%>
<%include include_form1.html%>
<%elsif ID=YOUR ID HERE%>
<%include include_form2.html%>
<%elsif ID=YOUR ID HERE%>
<%include include_form3.html%>
<%else%>
<%include include_form.html%>
<%endif%>

Regards,

Blake
Quote Reply
Re: [blakeb] Help needed with different form for different category In reply to
Glad it worked Cool

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: [webmaster33] Help needed with different form for different category In reply to
Hi, sorry it took me so long to get back to this and many thanks for replying.

However, I tried doing what you suggested but it still will only do that for the category id number I specify in the IF statement - I have about 6 main categories but within those I have getting on for hundreds of subcategories and want it to recognise any subcategory of say CATEGORY ID NUMBER 5 for instance - so any subcategories under that will then use a different include_form and a different link.html template too.

Any ideas anyone - is it possible to even do this this way or is there a much easier way to do it?

Any help greatly appreciated.

Thanks
Sal
Quote Reply
Re: [Sal2] Help needed with different form for different category In reply to
Well, then use category template feature of LSQL. Just create new category template for those categories where you want different forms, and use <%include form_categoryname.html%> within the template. The template can be the same, except the form filename you include.

The category template is inherited in the subcategories, so this way you can avoid using many if statements.

Hope that helps.

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: [webmaster33] Help needed with different form for different category In reply to
Hi,

Jack told me to do like this:

<%if ID==1 or ID==2 or ID==6%>

html_code_for_these_categories

<%endif%>

<%if ID==3 or ID==4 or ID==5%>

html_code_for_these_categories

<%endif%>

But the problem is if i have some 300 categories and subcategories and sub sub categories, it will time consuming.

Quote:


Well, then use category template feature of LSQL. Just create new category template for those categories where you want different forms, and use <%include form_categoryname.html%> within the template. The template can be the same, except the form filename you include.


Webmaster33, Can you explain it please? If i change the file name, it displays some tags are 'UNKNOWN TAGS'.

thanks.

Last edited by:

hegu: May 7, 2003, 6:20 AM
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
  1. Make a copy of your category.html to category_Computers.html
  2. Edit category_Computers.html, and insert a new form manually, or including a form from a different file using <%include add_form_Computers%>.
  3. Go to Admin/Browser/ select a category (now for example "Computers"), click EDIT, and search Category Template form text field. There you should type the category_Computers.html filename.
    Now all subcategories in Computer category will use the same template, thus the same form you used in category_Computers.html

If you do everything correctly, then this should work.

I hope this helps.

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: [webmaster33] Help needed with different form for different category In reply to
Hi,

What you said is for changing the html lay out for different categories. There is no form display in category.html. Users click on the 'ADD A LINK' to go to the form. So as you said, if i add a different form in each category template , when user clicks on 'ADD A LINK' he will go to original form.

thanks.
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
Oh, you are absolutely right! I must be tired. Blush Ok-ok, so we are talking about the add form.
I will think about it.

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: [webmaster33] Help needed with different form for different category In reply to
Thanks. Any help in this matter is really appreciated.

Because i am just sitting here with my 286 CATs and SUB CATs and don't know how to set up this add form thing.
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
Likely a global will be required. I will try to come out with something for you.

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: [hegu] Help needed with different form for different category In reply to
This global should check whether current category ID is subcategory of the examined category or not. Returns true if current category id, is same, or current category is child of the examined category.

Global name: is_child_category
Code:
sub {
my $catid_current = shift;
my $catid_check = shift;
return 1 if $catid_check eq $catid_current;
my @children = $DB->table('Category')->children($catid_check);
foreach (@children) {
return 1 if $_ eq $catid_current;
}
}
NOTE: code edited

Usage examples in add*.html template pages:
<%if is_child_category($ID, 123)%><%include add_form_123.html%><%endif%>
<%if is_child_category($ID, 130)%><%include add_form_130.html%><%endif%>
<%if is_child_category($ID, 131)%><%include add_form_131.html%><%endif%>

Input parameters:
1) The ID should the current category ID (hopefully it is, but if not, please correct it)
2) category we analyze if it's same with current category, or it is subcategory of it

Output:
- True if examined category id is same as current category
- True if examined category id is subcategory of current category

I did not test the global, but logically should work.
Let me know, if there will be any problems with it.

BTW: Well, could be possible to avoid the first input parameter, if really needed, but that current way was easier for me. Oh no, I'm not lazy! Just very lazy Wink

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...

Last edited by:

webmaster33: May 7, 2003, 8:19 AM
Quote Reply
Re: [webmaster33] Help needed with different form for different category In reply to
Some comments for improving your global.

1. You should replace 'eq' by '==', since you are comparing numeric values.

2. Also, you should return 0 or some other false value if your condition is not met.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Help needed with different form for different category In reply to
Thanks for your comments.
  1. Quote:
    You should replace 'eq' by '==', since you are comparing numeric values.
    Comparing numbers in perl using 'eq' or '==' doesn't matter. Perl will treat numbers as text in case when you use 'eq'. Result is the same.

  2. Quote:
    you should return 0 or some other false value if your condition is not met.
    Yeah, I was thinking about it, but I was not sure, if I need returning 0 or not. In my logic, if nothing is returned, it's assumed by template parser as false result. Isn't that true?


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...

Last edited by:

webmaster33: May 7, 2003, 8:41 AM
Quote Reply
Re: [webmaster33] Help needed with different form for different category In reply to
Hi,

Quote:


Usage examples in add*.html template pages:
<%if is_child_category($ID, 123)%><%include add_form_123.html%><%endif%>
<%if is_child_category($ID, 130)%><%include add_form_130.html%><%endif%>
<%if is_child_category($ID, 131)%><%include add_form_131.html%><%endif%>


These 123, 130, 131 are father IDs(main category IDs under Home). Right? So i have to create one form for each Main category?

thanks.
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
Not really. Doesn't matter, if category is a main category or not.
Using the 123 as parameter, means it will display the form in category with ID 123, and all subcategories of it (if the global works correctly).
This is what you wanted, isn't it?

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...

Last edited by:

webmaster33: May 7, 2003, 9:12 AM
Quote Reply
Re: [webmaster33] Help needed with different form for different category In reply to
Exactly that is what i wanted.SmileSmileSmile

With your global i can use it for a category or a sub category or sub sub category. Great. I will try it and post here.

Thanks.
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
Hi Webmaster33,

Not working. I am getting this error:

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

A fatal error has occured:

GT::SQL::Table (16908): Wrong argument passed to this subroutine. Usage: Must pass category id to children at /home/usrname/public_html/cgi-bin/resources/admin/Links/Category.pm line 293.

Please enable debugging in setup for more details.

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

This is what i did:

1. I saved your global as you said..

2. In the include_form.html I put the code like:

<%if is_child_category($ID, 231)%>
<tr><td>......</td></tr>
<%endif%>

Where did i went wrong?
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
This is because on main page, will not pass category ID number to add.cgi.

Try this code:
Code:
sub {
my $catid_current = shift;
my $catid_check = shift;
return 0 if $catid_current =~ /^\d$/;
return 0 if $catid_check =~ /^\d$/;
return 1 if $catid_check eq $catid_current;
my @children = $DB->table('Category')->children($catid_check);
foreach (@children) {
return 1 if $_ eq $catid_current;
}
}
EDIT: further checking added, to allow only numbers, as ID.

This will ignore the situation, when you are clicking add.cgi in home.html or no ID is passed.
Also I changed to avoid second input parameter to be 0, since it's the root category.

Hope that helps.

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...

Last edited by:

webmaster33: May 8, 2003, 9:47 AM
Quote Reply
Re: [webmaster33] Help needed with different form for different category In reply to
Hi,

I changed new global and put this html code in include_form.html:

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

<%if is_child_category($ID, 231)%>
<tr><td valign="top" BGCOLOR="#cacaff" align="right"><%body_font%><b>Section Two:</b></font></td>
<td align="left" BGCOLOR="#cacaff"><b>If you are submitting EBOOK:</b></font><br>
</td></tr>

<tr><td valign="top"><%body_font%>Version: </font></td>
<td>
<input class="button" name="Version" value="<%if Version%><%Version%><%else%><%endif%>" size="20"><br><%form_font%>(Like 1.0, 2.0.1)</font>
</td></tr>
<%endif%>

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

But the form is like before as usual even when i click the 'ADD A LINK' link under 231 directory.
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
Uhm, I made a mistake. I used if instead unless.
Corrected here:

Code:
sub {
my $catid_current = shift;
my $catid_check = shift;
return 0 unless $catid_current =~ /^\d$/;
return 0 unless $catid_check =~ /^\d$/;
return 1 if $catid_check eq $catid_current;
my @children = $DB->table('Category')->children($catid_check);
foreach (@children) {
return 1 if $_ eq $catid_current;
}
}

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: [webmaster33] Help needed with different form for different category In reply to
Hi,

I tried THREE methods. Nothing seems working.

1. Your global and <%if is_child_category($ID, 123)%><%include_form_ebooks.html%><%endif%> in add.html.


2. Your global and <%if is_child_category($ID, 123)%>HTML_code_here<%endif%> in include_form.html.


3. As Jack said:

<%if ID==231 or ID==232 or ID==233 ID==234%>HTML_code_here<%endif%> in include_form.html.



Where i am doing wrong?
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
Even if my global doesn't work, the third solution, said by Jack should work...
Try this:
<%if ID==231%>HTML_code_here<%endif%> in add.html

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: [webmaster33] Help needed with different form for different category In reply to
Hi,

I did a mistake. Instead of <%include include_form_ebooks.html%> i am keeping <%include_form_ebooks.html%>

This adjustment working with Jack's method. Not the global.(sigh)

Again at the same point... Now I have to use this format:

<%if ID==231 or ID==232 or ID==233 ID==234 ID==235 ID==236 ID==237 ID==238 ID==239 ID==240 ID==241 ID==242 ID==232 ID==243 ID==244 ID==245 ID==246 ID==247 ID==248 ID==249 ID==251 ID==252 ID==253 ID==254 ID==255 ID==256 ID==257%><%include include_form_ebooks.html%><%endif%>

Webmaster33, Thanks for your time, help and advice.Smile
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
You are missing lots of "or"'s from that tag.
Quote Reply
Re: [Paul] Help needed with different form for different category In reply to
Ooops...

Thanks Paul.Smile
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
Hmm.
Checked Category.pm. It seems children() method returns arrayref, not array.

Try this:
Code:
sub {
my $catid_current = shift;
my $catid_check = shift;
return 0 unless $catid_current =~ /^\d$/;
return 0 unless $catid_check =~ /^\d$/;
return 1 if $catid_check eq $catid_current;
my $children = $DB->table('Category')->children($catid_check);
foreach (@{$children}) {
return 1 if $_ eq $catid_current;
}
}

<%if is_child_category($ID, 231)%><%include include_form_ebooks.html%><%endif%>

Hopefully all bugs corrected now.

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: [webmaster33] Help needed with different form for different category In reply to
Quote:
foreach (@{$children}) { return 1 if $_ eq $catid_current; }

You could use grep for that.

Code:
return 1 if grep $_ eq $catid_current, @$children;
Quote Reply
Re: [Paul] Help needed with different form for different category In reply to
Yeah, thanks Cool

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: [webmaster33] Help needed with different form for different category In reply to
Hi,

I tried all methods but nothing seems working for me. So i used Jack's idea. It is working.

Thanks.
Quote Reply
Re: [webmaster33] Help needed with different form for different category In reply to
Hi,

Haven't thoroughly read this thread, but shouldn't you be allowing for ID numbers which have more than one digit in them? /^\d+$/

Laura.
Quote Reply
Re: [afinlr] Help needed with different form for different category In reply to
Yes, you are right Wink. Multiple numbers should be allowed.
It seems I was more inattentive than usual, so I went to LSQL to test & make working that global.

Here is the tested working is_child_category global:
Code:
sub {
my ($catid_current, $catid_check) = @_;
return 0 unless $catid_current =~ /^\d+$/;
return 0 unless $catid_check =~ /^\d+$/;
return 1 if $catid_check eq $catid_current;
my $children = $DB->table('Category')->children($catid_check);
foreach (@{$children}) { return 1 if $_ eq $catid_current }
}

You may wish to have implemented the optimization suggested by Paul, so here it is:
Code:
sub {
my ($catid_current, $catid_check) = @_;
return 0 unless $catid_current =~ /^\d+$/;
return 0 unless $catid_check =~ /^\d+$/;
return 1 if $catid_check eq $catid_current;
my $children = $DB->table('Category')->children($catid_check);
return 1 if grep $_ eq $catid_current, @$children;
}

Then use tags in add.html, or include_form.html this way:
<%set is_child_category_231 = is_child_category($ID, 231)%><%if is_child_category_231%><%include include_form_231.html%><%endif%>
<%set is_child_category_500 = is_child_category($ID, 500)%><%if is_child_category_500%><%include include_form_500.html%><%endif%>

Thanks Laura for pointing out that bug, Yogi for his comments, and Paul for his optimization suggestion.
Lars, finally you can enjoy this global.

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: [webmaster33] Help needed with different form for different category In reply to
Hi,

I said i tried Jack method and it is working. But the problem is if user left any 'Not Null - Yes' link fields the form is going back to 'add.cgi' not 'add.cgi?ID'

For example Title is set to Not null- Yes. If user enter the form at mydomain/add.cgi?231 and forgot to fill title. He will be pointing to the error and now he will be on add.cgi (default form) So even though i can present different forms for different categories, they are redirected to add.cgi default form, if they didn't enter a required field.

Webmaster33, is your global overcomes this?

Thanks.
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
Note:
The mydomain/add.cgi?231 format is bad.
The mydomain/add.cgi?ID=231 is good.

If you don't want to use my global, then don't use it.
However I thought you want to avoid typing such a lot if conditions... Wink

Quote:
He will be pointing to the error and now he will be on add.cgi (default form) ...
Well, yes, because it seems the ID isn't passed to the error page.
Just use my global, and add the following code to add.html pages, after <%include include_form.html%>:
Code:
<input type=hidden name='ID' value='<%ID%>'>

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: [webmaster33] Help needed with different form for different category In reply to
Is this the way in add.html?

<%set is_child_category_231 = is_child_category($ID, 231)%><%if is_child_category_231%><%include include_form_231.html%><input type=hidden name='ID' value='<%ID%>'><%endif%>

<%set is_child_category_500 = is_child_category($ID, 500)%><%if is_child_category_500%><%include include_form_500.html%><input type=hidden name='ID' value='<%ID%>'><%endif%>

Thanks.
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
No. The
<input type=hidden name='ID' value='<%ID%>'>
code is needed only once, and should not be placed within the if statement.

Place before
<input type="SUBMIT" name="add" value="Add Link">
code.

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: [webmaster33] Help needed with different form for different category In reply to
Hi,

Now i have another problem.Frown

When user logged and click on 'Modify a link', he selects the link and clicks submit, they are taken to default form NOT the form that i set to that category. Any suggestions?

Thanks.
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
Do you use the global?

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: [webmaster33] Help needed with different form for different category In reply to
No. With global i got this problem:

Example- say i have A,B,C,D categories. Global is taking the category and its sub and sub sub categories and presenting one form. If i want one or two sub categories under 'A' different form from the form of that category, i couldn't get it work.

So again i changed back to <if ID == 3... method.

thanks.
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
You didn't mention that until now.

Yes, I understand your problem.
Original supposed solution was: "Using the 123 as parameter, means it will display the form in category with ID 123, and all subcategories of it".

There is a workaround for that problem, but it just a limited solution, since you will not able to use include to get form from a file.
<%set is_child_category_123 = is_child_category($ID, 123)%>
<%set is_child_category_130 = is_child_category($ID, 130)%>
<%set is_child_category_131 = is_child_category($ID, 131)%>
<%if is_child_category_123%><%set result = 'aaaaaaaaaaaaaaaaaa'%><%endif%>
<%if is_child_category_130%><%set result = 'bbbbbbbbbbbbbbbbbb'%><%endif%>
<%if is_child_category_131%><%set result = 'cccccccccccccccccc'%><%endif%>
<%result%>

In some cases this will help you out.

However the approach of the problem was bad, so we need a different approach.
Seems you want a more complex solution, to have the form templates inherited down in the hierarchy, while you can override the used form template anytime in deeper categories.
I will try to come out with a solution for you, which will match that new approach above.

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: [webmaster33] Help needed with different form for different category In reply to
Quote:
You didn't mention that until now.


I didn't think of that until i put your global and customized everything and then scratched my head...

I gave you an email .Can you check that for me please and answer me?

thanks.

Last edited by:

hegu: May 12, 2003, 11:17 AM
Quote Reply
Re: [hegu] Help needed with different form for different category In reply to
Uh, please take/edit out my email from you last post, please!

I just finished the new global I mentioned, will post soon.

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: [webmaster33] Help needed with different form for different category In reply to
Quote:
Uh, please take/edit out my email from you last post, please!

Why?
Quote Reply
Re: [Paul] Help needed with different form for different category In reply to
Because I don't like to have my email in forums. Email parser engines will find my email and I will get a lot spams. I already get many of them, don't want more...

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...