• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with set_select( ) function - CI Validation Class

#11
[eluser]ontguy[/eluser]
This post has a simple rewrite for set_select in the CI Validation Class.
http://ellislab.com/forums/viewthread/69956/

...application/libraries/MY_Validation.php
Code:
function set_select($field = '', $value = ''){
  if ($field == '' OR $value == ''){
    return '';
  }
  $compareVal = isset($_POST[$field]) ? $_POST[$field] : $this->$field;
  if($compareVal == $value){
    return ' selected="true"';
  }
}

this allows you to set the load a default in the controller:
Code:
$this->validation->myselect = "select1";

then in the view:
Code:
<select name="myselect">
<option value="select1" &lt;?=$this->validation->set_select('myselect', 'select1'); ?&gt; >&lt;?=$row->name; ?&gt;</option>

I don't think it works with multiple selected items.

#12
[eluser]vee[/eluser]
this bug still not fix?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.