1

I am trying to implement following functionality in drupal:

  • From the admin interface add, edit, list multiple stores for a company. The store record would be: Store name, address, image and zip code. This will be like how its done in simple lists - a list of stores shows up with edit and delete links and a link to add a new store, thats all.

  • Provide a search box in the homepage (separate from the standard site search) which will allow users to enter a zip code and view the image, title and address of stores in that zip code ( No need for proximity search or anything)

What I have done so far:

For adding store information: created a new content type called 'Store Locator'' and added custom fields for required data. I unchecked promote to front page, so the added records do not show up in the homepage. This works pretty much how I want so that is fine.

The main challenge is to give a search facility for the stores. I created a view called store locator with rule set to show only 'Store Locator' content types. Added 'Table' as the format for display, and added the fields I want to see in the table. This view was created as a 'Page'

Now when I got to the view's URL, I can see a list of stores in the defined table format. My problem is that I need to add a search box in the front page where the user can enter a zip code and it will show this same view page, but with only matching records. Basically the custom search result page should be in the same table format and not like how the results gets displayed when a standard site search is done. I am at a loss on how to add a new search box in the home page, and how to link it to the view page with filtered results..

I am not looking for a complete answer to this problem, just some pointers on what area I should be looking at..I am pretty new to drupal and its pretty daunting to figure out which way I should explore more. I installed/uninstalled a lot of modules to see if they can do it, but they did not really help. Any pointers on which direction to explore would be highly appreciated!

3

As far as I understand you made 80% of the way. I think you can do the following:

  1. Add contextual filter to your view so you will be able to filter to results according to the zip code

  2. Use your custom module (if you don't have one, this will be a good time to create one) to define a custom block (use the following hooks - hook_block_info and hook_block_view)

  3. Create a custom form that will contain the search box and the submit button

  4. Make a custom submit handler that takes the field value (the zip code inserted by the user) and loads the views page with the inserted zip code (the contextual filter we defined in step 1 will allow it)

  5. Place the form in your custom block and place that sweet block in your homepage

References: Create custom form

Edit: By the way, the first comment is exactly what you need.

   function my_module_my_form_submit($form, &$form_state) {
    $first_name = $form_state['values']['first']; 
    $last_name = $form_state['values']['last'];
    drupal_goto("/my_view/".$first_name."/".$last_name);
}

Hope that helps.. Rotem

  • thank you for your answer! I will certainly try this.. will let you know how it goes – open_sourse Aug 25 '13 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.