Monday, June 27, 2011

Re: get input value to perform a custom search

You need to put the form input field inside a form and replace the link with an input button. Then check $this->data inside your search function.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 27 Jun 2011, at 20:00, Facu Siracusa wrote:

Hi all! I want to perform a search on the database depending on an
input from the user.
In the view I have this snippet of code:

<table>
       <tr>
            <td>
       <?php
          echo $form->input('Title to
search:',array('id'=>'inputfilter','name'=>'input','label'=>'Title to
search'));
       ?>
        </td>

        <td class="actions" >
            <div style='margin-top:35px' >
       <?php
       echo $this->Html->link(__('Filter', true), array('action' =>
'search')
       ?>
            </div>
       </td>

       </tr>
       </table>

In the controller:

function search($title)
{
           $films = $this->Film->find('all', array('conditions' =>
array('Film.titulo_original LIKE' => '%'.$title.'%'),
                                                           "OR" =>
array ('Film.titulo_alternativo LIKE' => '%'.$title.'%'),
                                                           "OR" =>
array ('Film.titulo_alternativo2 LIKE' => '%'.$title.'%')
                                                  ));
           $this->set('films', $films);
}

The question is, how can I recovery the text that the user typed in
the input field, and pass it as a parameter of the search method in
the controller??

Thanks!

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: