First set the options in the controller as to the available fields the
search can use (you can do so on your AppController::beforeRender() method
if the search form is displayed directly on the layout):

$fields = array (
        'surname' => 'Surname',
        'name' => 'Name'
);

$this->set('fields', $fields);

Then on the view inside the search form show the select box:

<?php echo $html->selectTag('Enquiry/field', $fields, null, array(), null,
false); ?>

Then modify the search() action accordingly (I've also removed things you
didn't want, such as: calling $this->render() and $this->render('search')
inside search() action is exactly the same, and it is not needed since
CakePHP will automatically render the view 'search' once action search() is
processed):

function search() {
        if(!empty($this->data)) {
                $conditions = array();
                $search_term = $this->data['Enquiry']['surname'];
                $search_field = $this->data['Enquiry']['field'];

                $conditions['Enquiry'][$search_field] = "LIKE
%{$search_term}
%";
                $query = $this->Enquiry->findAll($conditions);

                $this->set('data', $query);
        }
}

-MI

---------------------------------------------------------------------------

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de mike
Enviado el: MiƩrcoles, 21 de Febrero de 2007 07:11 a.m.
Para: Cake PHP
Asunto: seaching various feilds

I have implimented a search using the code below which works well, but
it only searches one field. What I'd like is a drop down box in the
view to select the feild to be searched (name, address, postcode,
etc). However i'm not sure how to reflect this in the controller code.
I wonder if someone could give me a hint?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to