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: [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: [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