Gossamer Forum
Home : Products : Gossamer Links : Discussions :

different input form for different sub-categories

Quote Reply
different input form for different sub-categories
Need some advice...

If different sub-categories have a different data set what is the best way to approach this. The main category is set to each city, then the sub-categories are jobs, roommates, apartments, etc.

I need the add form and detail page to have different information depending on the category. If they are posting in the apartments section they would input rent and number of bedrooms. If in the job section they would input the type of job, full or part-time, etc

What is the best way to approach this? A template for each sub-category of the city. One for jobs, one for apartments and one for roommates?

Or would it be better to us an <%if > statement on the add template. That way if they are trying to post in the apartment section the appropriate information would be added in.

Any advice is appreciated!
Quote Reply
Re: [Soren] different input form for different sub-categories In reply to
You could do this in several ways. The simplest method would be to add the following to your include_form.html template:
Code:
<%if ID = '123'%>
form1
<%elsif ID = '234'%>
form2
<%endif%>
If the forms are large, you could put the forms in their own files and <%include%> them.

The more sophisticated method (only needed if you have a ton of different templates needed) would be to add a column to the Category table that specified which template to use. Then in the include_form.html template just do:
Code:
<%if FormTemplate%>
<%include $FormTemplate%>
<%else%>
default form here
<%endif%>
(assuming you named the columns FormTemplate.

In your case, I believe you would base the template decision on what root category they were in. So you could use the category Full_Name to decide. Using the first method I described above, you could have something like:
Code:
<%if Full_Name starts 'Apartments/'%>
<%include include_form_apartments.html%>
<%elsif Full_Name starts 'Jobs/'%>
<%include include_form_jobs.html%>
<%endif%>
This assumes that you have db_gen_category_list set to No and that only one category has been passed to add.cgi. To write more robust template code, it should check category_loop like the existing include_form.html template does.

Adrian
Quote Reply
Re: [brewt] different input form for different sub-categories In reply to
This is really very interesting!

But how about different columns which are required in different categories?

I.E. "number_of_bathrooms" is required in "Real Estate" category, but user want to add a record in "Cars" category - what then?

Secondly, if someone want to search only for job opportunities does he/she have to see a special "search_jobs.cgi" page with only fields relevant to jobs?

Many thanks in advance ..
Quote Reply
Re: [brewt] different input form for different sub-categories In reply to
Quote:
The more sophisticated method (only needed if you have a ton of different templates needed) would be to add a column to the Category table that specified which template to use. Then in the include_form.html template just do:
Code:
<%if FormTemplate%>
<%include $FormTemplate%>
<%else%>
default form here
<%endif%>

I am trying to get this to work with no luck. This will be for multiple cities. With each city being the main category and topics being sub-categories I need to pull in the form for different sub-categories such as roommates, rentals, textbooks. If I understand this right I can add a column to the category, then use an "if"
statement to pull in the specific form for that category. I think I might have an issue with the column settings

Current settings.


Quote:
Column Type Char
Column Index None
Column Size 100
Not Null no
Default Formrentals
Form display Formrentals
Form Type text
Form Size 40
File Save Method Hashed

Thanks in advance!