How can I set the default for a Dropdown (created using the Form Helper) by using the Form_validation library in CodeIgniter?
In my vi开发者_如何学编程ew, I have:
$form_prop = 'class="inp_step" id="bedrooms"';
echo form_dropdown( "bedrooms", array( null, 0,1,2,3,4,5,6,7,8,9,10), null, $form_prop );
So how do I stick a
<?php echo $this->validation->set_select('myselect', 'one'); ?>
in there?
The third parameter to form_dropdown(), which you are declaring as 'null', is where you set the default.
I generally code this as a variable, which either gets populated from a database field, or from the user selected value for the field. In the latter case, you have named the select 'bedrooms', so you would set the default as:
$var = set_value('bedrooms');
echo form_dropdown( "bedrooms", array( null, 0,1,2,3,4,5,6,7,8,9,10), $var, $form_prop );
When setting it from a database field:
$var = $db_rec['bedrooms'];
echo form_dropdown( "bedrooms", array( null, 0,1,2,3,4,5,6,7,8,9,10), $var, $form_prop );
精彩评论