开发者

How can I set the default for a Dropdown (created using the Form Helper) by using the Form_validation library in CodeIgniter?

开发者 https://www.devze.com 2023-01-03 08:17 出处:网络
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 );

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 );
0

精彩评论

暂无评论...
验证码 换一张
取 消