Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Help needed with different form for different category

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