populating search box fields and directing the user to the correct place

6 posts by 2 authors in: Forums > CMS Builder
Last Post: June 26, 2008   (RSS)

Hello all,

I am pretty new to php and mySql but am trying my best. I have a few things that I want to do but am not even sure if they are possible and if so, where to begin.

We have a search box on our homepage, with help from your forums and trial and error I was able to create a dropdown list that is populated by one of our tables in the database.(I created a separate editor and added our categories as listings.) Inside each of these categories are subcategories.

Is there a way to populate a subcategories drop down list based on what the user selects for the category?
(ex: There is an Automobile Rentals category, inside that are subcategories such as Sports Cars, Classic Cars, etc.)

Also, I have setup different "viewers"(templates) for each category (ex: Automobiles has its own page, which is different from say, Books and Audio) When the user chooses Automobiles and clicks "Sumbit" I want the results to display on the viewer (template) for Automobiles. If the user chooses Books and Audio, the results should display on the Books and Audio viewer(template).


The search box in question is located here:
http://www.rentittoday.com/portal_page.php


Thank you in advance for your help.
Jason Glass

Re: [rentittoday] populating search box fields and directing the user to the correct place

By Dave - June 24, 2008

Hi rentittoday,

It sounds like what you want is "chained select pulldowns". I found an example here: http://bonrouge.com/~chain_select_js and more here http://www.google.ca/search?q=javascript+chained+selects.

Basically you have two or more select (pulldown fields), and when you select the first one it updates the second one with "sub options".

This is a bit of a mini-project all by itself. You need to find a javascript widget that does that the way you want, then create a CMS Builder viewer to output the code in the format the widget wanted. It's certainly possible but would be a bit of work (we can also do it as a custom project if desired).

Another option would be to create your categories use the "category menu" type. It will create a field for you called "breadcrumb" that you can use as the value for the pulldown so you'd have options like this:
Automobiles
Automobiles : Sports Cars
Automobiles : Class Cars
etc.

So there's two options. If you want to go with the chained selects the first step would be to get it working in plain html outside of CMS Builder, then have CMS Builder generate the needed code.

Hope that helps! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] populating search box fields and directing the user to the correct place

Thank you. I was able to create the chained selects like I wanted and they are up and working. I just added a few options for now.

http://rentittoday.com/portal_page.html

Now my questions are:
How do I get the search query operational?
How do I get it to call the correct template/viewer, based on the category? (The subcategory should not determine the viewer, only the category, ex. Classic cars should appear in the Automobiles viewer, Sports cars should also appear in the Automobiles viewer.)
Jason Glass

Re: [Dave] populating search box fields and directing the user to the correct place


Ok, to get the chained select fields to work, I had to stop populating the category fields in my search box. I put the categories and subcategories in by hand.

In the CMS Builder we have 22 different section editors; one for each category (ex. Automobiles, Boats and Yachts, etc)

In each of the Sections, (which are our categories), we have a list field called subcategory.

I have looked at all the documentation for CMS Builder and I'm beginning to think that our search box may need to be a multi-search thing? I say that because we will need to search ALL of the listings in ALL the section editors.
For example I added some test listings into a few categories. But when I search using the keyword text box I setup, it only pulls the automobiles listings.



> Do u want an entirely different page or just a different banner, stylesheet, etc?

There will be different content on each page so I think they need to have their own. Thank you for the code and I get the concept, so I think I will be ok with that part. But where do I put that code into?

Thank you again.
Jason Glass

Re: [rentittoday] populating search box fields and directing the user to the correct place

By Dave - June 26, 2008

Are all your sections very different? Do they have different fields? If possible it's often much easier to have one combined section with an extra field for "Type" which would be a pulldown of Automobiles, Boats, etc.

You'd put the code to include the different templates in the search results page. In fact, since it loads another page you could just have that alone... Or maybe load the records first:

<?php

// load records here
// ...

// load template to display them in.
if ($FORM['mainCategory'] == "autos") { include "autoResults.php"; }
else if ($FORM['mainCategory'] == "boats") { include "boatResults.php"; }
else { include "generalResults.php"; }
exit;

?>


Hope that helps!
Dave Edis - Senior Developer
interactivetools.com