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: [rentittoday] populating search box fields and directing the user to the correct place

By Dave - June 25, 2008

Nice job! :)

What is your categories field called? What you need to do is name your search field after the editor fieldname you want to search. Like this:

http://rentittoday.com/template_page_results.php?category=Autos

You can read more about the automatic search options here: http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

You'll want to think about what you want it to do if the user doesn't select a subcategory or whether you want that field to be required. Some searches you'll be able to do with the automatic built in features, others could require custom programming or some PHP code.

>How do I get it to call the correct template/viewer, based on the category?

Do you want an entirely different page or just a different banner, stylesheet, etc? Banner/stylesheet is easier to manage. Either way, you can get the value of a field you submitted through the form with $FORM['fieldname'] such as $FORM['mainCategory']. So you could have some code like this:

<?php

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

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