Custom search form in Drupal 6: Views/Panels or custom sql?

1k views Asked by At

I use CCK in Drupal 6 and I need to build a search form in Drupal with 8-10 fields used as a filter. When the user submits the form I need to make a query on the DB applying filters and presenting the result on a table.
I know how to do this programmatically by building dynamically the SQL-where condition (joining node and content_type_xyz tables) but I would be interested in learning how to do it in the "Drupal way". I think I would have to use Views and Panels but I don't know if they can be easily implemented in situations like this. I've tried to build some sample views but I think to be faster in creating code by hand.

2

There are 2 answers

0
DrColossos On

If you want custom searches you need IMO to do 2 things:

  1. Hook yourself into _search so you can use Drupal's display for the results. Inside this form, you can create your queries for the database or load other content as you wish, just be sure to use pager_query.
  2. Extend the search form that already exists or built your own. I suggest buliding your own. use what is already existing from Drupals search form. This way, you have a clean way of how to do this.

There is actually no need to use any fancy modules (that doesn't mean you should rule them out, but a search is something so esential that it is quite well handled with the basics).

Using the above, you'll get a native search form with all it's power and can make use of global paging options.

0
cjm2671 On

If you do it using views you will only be limited to the filtering you can do using SQL. Views is an SQL builder, and does not contain any 'proper' search functions. That said, it sounds like Views will do what you want; if you create filters under views and then click 'Expose this filter', you will suddenly see fields that allow the user to enter something to filter by appear.