Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Help needed with different form for different category

(Page 1 of 2)
> >
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
> >