Question

I am having a problem with the form select helper. On my page I have two forms.

One is a quick search form. This one uses state_id. Upon searching in URL: state_id:CO This will auto select the correct value in the drop down.

However, when I search with the advanced form. The Field is trail_state_id and in URL: trail_state_id:CO For some reason it will not default it to the correct value. It just resets the form to no selections. The values are searhed properly, just the form helper is not recognizing that a field with the same name in the url is set. Any thoughts?

<?php 
class Trail extends AppModel {
    public $filterArgs = array(
        array('name' => 'state_id','field'=>'Area.state_id', 'type' => 'value'),
        array('name'=>'trail_state_id','field'=>'Area.state_id','type'=> 'value'),
        );
    }

?>

in URL: trail_state_id:CO

<?php
    echo '<h4>State*:</h4><div>'.$this->Form->select('trail_state_id', $stateSelectList, null, array('style'=>'width:200px;','escape' => false,'class'=> 'enhanced required','empty'=> false));
    ?>
Was it helpful?

Solution

Using the 3rd argument in the helper you can set a default. I did it the following way;

echo '<h4>State*:</h4><div>'.$this->Form->select('trail_state_id', $stateSelectList, (empty($this->params['named']['trail_state_id']) ? null: $this->params['named']['trail_state_id']), array('style'=>'width:200px;','escape' => false,'class'=> 'enhanced required','empty'=> false));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top