Search Tools - setting default option

Permalink
I've already messaged the Search Tool developer but not heard back yet. Has anyone used the optional parameter in the controller renderAttributeForm() to pass a custom default option?

I think my lack of php multi-dimension arrays knowledge is really the only issue. I'd appreciate help.

The function I am calling is -

public function renderAttributeForm($akID,$extras=array()) {
         $form = Loader::helper('form');
         if (!is_numeric($akID)) {
            switch ($akID) {
               case 'SEARCH_TOOLS_RADIUS_SEARCH':
                  echo $form->text('zip');
                  $radius = array();
                  $radius[3] = '3 '.$this->radiusUnits;
                  $radius[10] = '10 '.$this->radiusUnits;
                  $radius[75] = '75 '.$this->radiusUnits;
                  $radius[100] = '100 '.$this->radiusUnits;
                  echo $form->select('radius',$radius,$this->radiusDefault);
                  echo '<input type="hidden" name="radiusUnits" value="'.$this->radiusUnits.'" />';
                  echo '<input type="hidden" name="radiusAKID" value="'.$this->radiusAKID.'" />';
               break;



And I want to pass a new defaultValue in using -

<?php $controller->renderAttributeForm($fid, $extras = array ('defaultValue' => array ('By ' . $akLabels[$fid],''))); ?>



However I never get the required default value. I tried swapping the two values in the 2nd dimension. Am I creating the array incorrectly?

Many thanks.

Steve.

stevegibbings
 
stevegibbings replied on at Permalink Best Answer Reply
stevegibbings
OK after sleeping on this I found the issue was in the Search Tools AddOn code. The $extras array gets overridden and emptied so the optional parameter does nothing.

Below is the revised code with the line commented out which allows the value to be set.

public function renderAttributeForm($akID,$extras=array()) {
         $form = Loader::helper('form');
         if (!is_numeric($akID)) {
            switch ($akID) {
               case 'SEARCH_TOOLS_RADIUS_SEARCH':
                  echo $form->text('zip');
                  $radius = array();
                  $radius[3] = '3 '.$this->radiusUnits;
                  $radius[10] = '10 '.$this->radiusUnits;
                  $radius[75] = '75 '.$this->radiusUnits;
                  $radius[100] = '100 '.$this->radiusUnits;
                  echo $form->select('radius',$radius,$this->radiusDefault);
                  echo '<input type="hidden" name="radiusUnits" value="'.$this->radiusUnits.'" />';
                  echo '<input type="hidden" name="radiusAKID" value="'.$this->radiusAKID.'" />';
               break;
matogertel replied on at Permalink Reply
matogertel
Hi Steve, sorry you caught me in the weekend. Thank you for your post above. I will have a look and update my code. Does this answer your other query as well?
matogertel replied on at Permalink Reply
matogertel
Odd, I wrote that code some time ago and now I wonder if I put that on porpoise to get around some hidden c5 bug, or I was playing with it while debugging and left it there by mistake. Anyway, now it makes sense to comment it out, and hopefully it won't be breaking anything else down the line.
stevegibbings replied on at Permalink Reply
stevegibbings
Hi, yes I'm all sorted now.

(edited)

I've also added the ability to recurse into sub-pages for searching in my code so a search from /news also searches in /news/current-affairs and /news/celebrity.

I'm unsure as yet how I'll make this available to others but I think it might be useful.

Steve.