select box not showing first item in list

Permalink
Hello,
I'm sure there is a simple solution to this, but I cannot find where/how I can stop a select box in my contact form displaying '----'
when the page loads instead of the first item in the list, or at the very least the words 'please select'.

Just to make it more irritating, I'm sure I've done this before, but I've looked though every bit of code I can find and still can't find anywhere I can edit this. Can anyone help please,

Thank you in advance,
Bek

 
bbeng89 replied on at Permalink Reply
bbeng89
This may be a lot of work for such a small thing (and there could possibly be a better way of doing this) but one way you can do it is by overriding the block controller. Specifically you need to override the loadInputType() function in the MiniSurvey class.

So if you create an override controller at /blocks/form/controller.php you will want to set it up like this:

<?php
defined('C5_EXECUTE') or die(_("Access Denied"));
class FormBlockController extends Concrete5_Controller_Block_Form {}
class FormBlockStatistics extends Concrete5_Controller_Block_FormStatistics {}
class MiniSurvey extends Concrete5_Controller_Block_FormMinisurvey {
}
?>


Now you will want to copy the whole loadInputType() function from /concrete/core/controllers/blocks/form_minisurvey.php and paste it into your override. Then in the switch you can change the default option text (for me this is line 35). Or I think you could remove it all together. So to have the default option say ----SELECT---- the whole override controller would look like this:

<?php
defined('C5_EXECUTE') or die(_("Access Denied"));
class FormBlockController extends Concrete5_Controller_Block_Form {}
class FormBlockStatistics extends Concrete5_Controller_Block_FormStatistics {}
class MiniSurvey extends Concrete5_Controller_Block_FormMinisurvey {
   function loadInputType($questionData,$showEdit){
         $options=explode('%%',$questionData['options']);
         $msqID=intval($questionData['msqID']);
         $datetime = loader::helper('form/date_time');
         switch($questionData['inputType']){         
            case 'checkboxlist': 
               // this is looking really crappy so i'm going to make it behave the same way all the time - andrew
               /*
               if (count($options) == 1){
                  if(strlen(trim($options[0]))==0) continue;


Like I said, it is possible there is a better way of doing this but it seems to work for me.

I hope that helps.

Blake
planist1 replied on at Permalink Best Answer Reply
planist1
I think the default value is coming from the root/concrete/core/controllers/blocks/form_minisurvey.php file around line 241.
case 'select':
               if($this->frontEndMode){
                  $selected=(!$_REQUEST['Question'.$msqID])?'selected="selected"':'';
                  $html.= '<option value="" '.$selected.'>----</option>';               
               }
bek replied on at Permalink Reply
Thank you for both taking time to answer my question.

Planist1 you are spot on, thank you - that's how I did it previously, but I just couldn't remember where the file was. I'm going to make sure I write it down in my C5 docs now :)
bbeng89 replied on at Permalink Reply
bbeng89
Glad you were able to get it working. Just to clarify, you will want to make sure you override the function using the process I described in my previous post rather than editing the file directly. If you just edit the file directly your changes will be lost when you update concrete5. You may already know all of this but I just figured I would clarify for anyone reading.

Best of luck

Blake
planist1 replied on at Permalink Reply
planist1
Glad you got it working as well. Definitely agree with Blake about using the override function.
bek replied on at Permalink Reply
Hi, yes thanks for mentioning this, it's exactly the sort of thing I find quite easy to forget to do :)
grafoman replied on at Permalink Reply
Any idea on how to get this to work for Concrete 5.8?