How to create a Drupal 6 user form displaying results on a page?

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

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

SEARCH FORM has 3 text boxes but is not required. "First name", "last name", "age"

whichever type of user I would like to display results in the CENTER part of the template.

Obviously the form will submit the variable as $_POST

but then on the results page, if there are more than 5 results, I want to add pagination.

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

I would like to have a cleanURL like /search//Smith/24

or search/John//15

or search/John/Smith/40

for the answer "first name, last name, age" and then when using pagination adding /search/john/smith/40/page/3

?

+2


source to share


2 answers


Okay, googletorps second suggestion first consider the views solution first , as it can save you quite a lot of custom coding. However, I often find myself in a position where the views-based solution is only 80% of what I need, and adding the missing 20% ​​with views can be more work than a custom solution from the start - view views with expose filters and see if it fits.

If it isn't, here are some tips you should start with a custom solution:



  • As far as the search form goes, block is the right way to go. Take a look at hook_block()

    how to create it (you will need to implement at least a "list" of operations and a "view" for this)
  • The placement will happen via build / block as you said
  • In view mode, you must create your own shape. Take a look at the Drupal Quickstart and Reference APIs (don't create your own forms by hand - the Drupal Forms API just takes a little getting used to and will save you tons of time down the road).
  • For result pages, you must register your page callback function for the paths you want, see hook_menu()

    .
    • Warning: Your suggested "search / ..." path will contradict Drupals constructs in the search path, so you can choose a small option (like "search / people / ..." or "popular search /" or the like).
  • To create links in Drupal use the l () function
  • For pagination, you can use theme_pager

    , but it depends on how your actual search query is obtained, since it expects an array of query string parameters to build the query
+5


source


You can do it as you describe. You will need to use hook_menu to create urls, hook_block to create search form block, and then use l () function to create links. However, doing all this in your own module will take a long time. Making queries for searches, etc. Instead of what I would recommend you do, it would be to use the views module for all of this. With it, you can easily create a search form, but using the open filters, you can create a page and a block for it, make pagination and with just a few clicks. So even if you are a good PHP developer, your best bet in this case is to just use what Drupal provides as the views module and install it, with AI instead of writing a bunch of code. If you want to create your own module,take a look at these functions at api.drupal.org where you can find documentation for the drupal core.



+1


source







All Articles