views:

1189

answers:

2

I want to build site with a search form on LEFT and RESULTS in content(center) part.

I know how to create modules .. but how do I assign their location ? OR should I place SEARCH FORM as BLOCK and assign them to LEFT in build/block/.

SEARCH FORM has 3 textboxes, non of them is required. "name","surname","age"

whatever user type in I'd like to display a results in template's CENTER part.

obiously form will send variable as $_POST

but then in result page if there is more than 5 results I want add pagination.

SO how should i build links for <a href="?"

I'd like to have cleanURL like /search//Smith/24 or search/John//15 or search/John/Smith/40 for responding "name,surname,age" and then when using pagination by adding /search/john/smith/40/page/3 ?

All i need is pro. advise. I'm good php dev. just not that well familized with Drupal.

+1  A: 

You could do this the way you describe. You would need to use hook_menu, to build the urls, hook_block to make the search form block, and then use the l() function to make the links. However doing all this in your own custom module would require a lot of time. Making the queries for the search etc. Instead what I would recommend you to do, would be to use the views module for all this. With it you can pretty easily create a search form, but using exposed filters, you can create a page and a block for it, do pagination and all that just doing a few clicks. So even though you are a good php dev, the best thing to do in this case is to simply use what Drupal provides in the form of the views module and set this up, with the AI instead of writing a bunch of code. If you do deside to make your own module, take a look at those functions at api.drupal.org, where you can find the documentation for drupal core.

googletorp
and then use the l() function to make the links what is l() ?
David King
+1 for looking into views first
Henrik Opel
@David: l() is a Drupal build in function to create links - see http://api.drupal.org/api/function/l/6
Henrik Opel
+4  A: 

Ok, first up, I second googletorps suggestion to look at a views based solution first, as it can save you quite some custom coding. However, I often find myself in a position where a views based solution turns out to offer only 80% of what I need and adding the missing 20% with views can be more work than a custom solution right from the start - check out views with exposed filters and see if it fits.

If it doesn't, here are some hints that should get you started for a custom solution:

  • As for the search form, a block is the right way to go. Take a look into hook_block() for how to create one (you'll need to implement at least operations 'list' and 'view' for this)
  • Placement would happen via build/block as you said
  • On operation 'view', you would build your form. Take a look into the forms API Quickstart and reference for form handling in Drupal (do not build your own forms manually - the Drupal forms API needs only a bit of getting used to and will save you tons of time in the future)
  • For the result pages, you'd register your own page callback function for the paths you want, see hook_menu() for this.
    • Warning: Your proposed path 'search/...' would conflict with Drupals build in search path, so you might consider choosing a slight variation (e.g. 'search/people/...' or 'peoplesearch/' or the like)
  • For link creation in Drupal, use the l() function
  • For pagination you might be able to use theme_pager, but this depends on how straight your actual search query turns out, as it expects an array of query string parameters to build the query
Henrik Opel
excellent help ;)thanks
David King
+1 Spending to the time to make links to functions and being thorough.
googletorp