Вы здесь

форма поиска по значениям полей

Добрый день

У меня есть следующий вопрос, возможно кто то сможет помочь...

Задача стоит такая. Сайт посвящен автомобильной тематике. Соответственно есть подраздел о купле продаже автомобилей.

Создал тип содержимого "продать авто",
поля:
taxonomy - категория "марка автомобиля" (газ, ваз, хонда и тд),
CCK - цена (число, цел) ,
CCK - модель (текст),
CCK - Год выпуска (число, цел),
CCK - фото (img.field)
Вот вроде минимальная форма ввода характеристик авто. Первый вопрос - насколько сложно сделать так чтобы после выбора марки, в поле модели появлялся список моделей этой марки, то есть если марка - хонда, то в моделях появился бы список - Civic, Accord и тд. ? (в принципе это не критично, но было бы интересно реализовать именно та средствами друпала не прибегая к кодированию.)

Вторая, основная задача - поиск. Нужно создать простую систему поиска. Основные критерии расширенного поиска:
- задавать условия для "года выпуска": от -до (например найти записи с значением "год выпуска" от 1997 до 2002)
- задавать условия для "цена": от-до ( например найти записи с значением "цена" от 40000 до 150000).

Можете посоветовать вариант решения этой задачки под друпал?...

Был на форуме UberCart.org , там судя по топикам стоит такой же вопрос, пока остающийся без решения.
В этой системе реализован каталог продукции и система платежей, но поиска с параметрами (по цене например) не существует. (Возможно я плохо ищу)

Заранее спасибо за идеи :)

Комментарии

Изображение пользователя kabiev

вот нашел, возможно кому то пригодится.
http://drupal.org/node/164471

For the last three days I was fighting with filters. I was trying to find a way to filter nodes by one field (CCK price) to get results where the price would be in some range.

User TKS has come up with a solution, but it didn't work for me. (http://drupal.org/node/150248) Thanks Troy for your time and help!
And then with the help of Russian drupaller Piyavkin I finally made it work.

So here we go:

I assume that you have Drupal, Views and the CCK module installed.
In my case I had the CCK Decimal field where I'm saving the prices of items. The goal was to make a small form where the user will enter a price range and/or other search parameters and then Views should display those nodes.

1) Create your custom content type (CCK).
2) Add a page view. Select provide page view, use the pager and specify all the settings you need.
3) In the Filters area, add "Node: Published Equals YES"
4) Add "Decimal: Price (field_price) is greater then or equals to 1"
5) Add "Decimal: Price (field_price) is Less than or Equal to 10000000000"

Add the following code to the Argument handling code area.

<?php
if($_GET['pr_from']) { $lowend = $_GET['pr_from']; } else { $lowend = 1; }
if(
$_GET['pr_to']) { $highend = $_GET['pr_to']; } else { $highend = 10000000000; }
/***************************************************************************/
$view->filter[1]['value'] = $lowend;
$view->filter[2]['value'] = $highend;

$view->is_cacheable = 0;
return
$args;
?>

Ensure that $view->filter[X] has the right indexes. Getting them is very easy. Think of Filters as arrays and count from the top of the filter list to the bottom (start counting with 0).
So in our case 0 is node published, 1 is "Decimal: Price (field_price) is greater then or equals to 1" and 2 is "Decimal: Price (field_price) is Less than or Equal to 10000000000".

You may notice that in the Argument handling code area there are $_GET['pr_from'] and $_GET['pr_to']. Those are GET variables that I'm passing from the form to the Views.
Form:

<?php
<form id="search_form" name="search_form" method="get" action="http://www.example.com/view_url">
   
from:
    <
input type="text" name="pr_from" />
   
to:
    <
input type="text" name="pr_to" />
   
title has:
    <
input type="text" name="ttxt" />
   
shop id:
    <
input type="text" name="shop" />
    <
br />
    <
br />
    <
input type="submit" name="Submit" value="Search" />
    <
input class="cancel" type="submit" name="close_btn" value="Cancel" />
</
form>
?>

That's the way you pass parameters from the form to the View.

But you can make it a little bit more powerful, by extending the argument handling code:

<?php
if($_GET['pr_from']) { $lowend = $_GET['pr_from']; } else { $lowend = 1; }
if(
$_GET['pr_to']) { $highend = $_GET['pr_to']; } else { $highend = 10000000000; }
if(
$_GET['ttxt']) { $ttxt = $_GET['ttxt']; } else { $ttxt = ''; }
if(
$_GET['shop']) { $owner_shop = array($_GET['shop']); } else { $view->filter[4]['operator'] = 'NOR'; $owner_shop = array("-10"); }
/***********************************************************************************************************************/

$view->filter[1]['value'] = $lowend;
$view->filter[2]['value'] = $highend;
$view->filter[3]['value'] = $ttxt;
$view->filter[4]['value'] = $owner_shop;

$view->is_cacheable = 0;
return
$args;
?>

In the Filters area add two more filters:
1) Node: Title Contains Any Word
2) Node: Author Name is one of (choose whatever you like we will overwrite this in the argument handling code area)

And again don't forget to check $view->filter[X] indexes

If the user enters something in Title field of the search form, Views will look for the nodes which have that word in the title and the price is in the range of xx to zzz.
Also if the user enters an Author ID then Views will filter by this author. If not, Views will show all authors.

I hope my explanation is clear to you guys and this will be helpful for someone.
Cheers,
mixey

Изображение пользователя kabiev

очень полезный модуль для решения первой задачи
http://wimleers.com/demo/hierarchical-select

Изображение пользователя Mr. Bean

Полностью согласен с тобой