Codeigniter - 表单助手 set_select()
如何在 codeigniter 中的下拉数组上使用 set_select() (表单助手的一部分):
它用于记住用户选择了哪个选项。
$guide_options = array('investments' => 'Investments',
'wills' => 'Wills',
'tax-planning' => 'Tax planning',
'life-insurance' => 'Life insurance',
'currency-exchange' => 'Currency exchange',
'retirement-planning' => 'Retirement planning',
'international-healthcare' => 'International healthcare',
'savings-plans' => 'Savings plans',
'education-planning' => 'Education planning',
'sipps' => 'SIPPS',
'qrops' => 'QROPS',
'qnups' => 'QNUPS',
'mortgages' => 'Mortgages',
'other' => 'Other service'
);
echo form_dropdown('guide', $guide_options, 'investments');
此处的表单助手指南:http://codeigniter.com/user_guide/helpers/form_helper.html
How can I use set_select() (part of the form helper) on my dropdown array in codeigniter:
It is used to remember which option the user has selected.
$guide_options = array('investments' => 'Investments',
'wills' => 'Wills',
'tax-planning' => 'Tax planning',
'life-insurance' => 'Life insurance',
'currency-exchange' => 'Currency exchange',
'retirement-planning' => 'Retirement planning',
'international-healthcare' => 'International healthcare',
'savings-plans' => 'Savings plans',
'education-planning' => 'Education planning',
'sipps' => 'SIPPS',
'qrops' => 'QROPS',
'qnups' => 'QNUPS',
'mortgages' => 'Mortgages',
'other' => 'Other service'
);
echo form_dropdown('guide', $guide_options, 'investments');
Form helper guide here: http://codeigniter.com/user_guide/helpers/form_helper.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
试试这个:
http://codeigniter.com/forums/viewthread/97665/
Try this:
http://codeigniter.com/forums/viewthread/97665/
您不必使用 set_select() 因为您已经在 from_dropdown() 中定义了所选项目
为了更好地理解,请参阅下面的代码和输出
You Don't have to Use set_select() as you are already defining selected item in from_dropdown()
For better understanding refer below code and output
这是 set_select() 的工作示例
完整代码:
或者您可以使用纯 PHP 方法:
Here's a working example of set_select()
Full code:
Or you can use a pure PHP approach:
要使用 set_select,您需要有相关字段的验证规则。请参阅我对类似问题的回答:
Form_dropdown 中的 CodeIgniter select_value
To use set_select you need to have a validation rule for the field in question. See my answer to a similar question here:
CodeIgniter select_value in form_dropdown
如果您使用 html 代码而不是帮助程序生成,则可以使用
set_select
。虽然你可以做这样的事情
set_select
you can use if you produce with html code not with helper.Although you can do something like this