Question

In CakePHP 2.4, how do I pass a form directly to a controller parameter? My controller takes a parameter in the format /Model/index/by:keyword, however FormHelper keeps inserting a question mark and an equals sign into the URL: Model/index?by%3A=keyword.

This is the form I've been using. Is there any way to change this default behavior?

echo $this->form->create('Post', array('action' => '/index', 'type' => 'get', 'class' => 'navbar-form')); 
echo $this->form->input("by:", array('label' => '', 'placeholder' => 'Search', 'class' => 'form-control')); 
echo $this->form->end();
Was it helpful?

Solution

I'd try to create the form like this:

echo $this->Form->create('Post', array('type' => 'GET', 'url' => array('controller' => 'yourpostcontroller', 'action' => 'search')));
echo $this->Form->input('search', array('class' => 'form-control'));
echo $this->Form->button('Search', array('div' => false, 'class' => 'btn'));
echo $this->Form->end();

In your "Search" action (inside the controller) do not forget to read the request:

if(!empty($this->request->query['search']) ...{
    //do something
}

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top