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)

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