【问题标题】:How to edit user form which had dropdown in codeIgniter?如何编辑在codeIgniter中有下拉菜单的用户表单?
【发布时间】:2013-03-09 13:27:00
【问题描述】:

我在管理模块中有用户。针对每个用户行,我都有编辑用户选项。当管理员单击该编辑用户选项时。他将看到带有字段的编辑用户表单。在这些表单字段中,其中一个字段是下拉列表,它是用户配置文件类型。

现在我将从数据库中获取有关该用户的所有详细信息的数组,该用户的管理员编辑名为$user_details。但是从数据库中我会得到字段名称中的用户配置文件 ID,例如 $user_details['profile_id'];

同时,我有另一个数组,它将配置文件 ID 与配置文件名称映射。也就是$profile

现在,当管理员首先单击编辑时,他需要在编辑之前查看该用户的 profile_name。当他单击该下拉菜单时,他需要查看可用于更改的配置文件类型。

我不知道该怎么做。

这就是我尝试过的

<label>Profile: <?php echo form_error('profile'); ?></label> <br />
       <select class="styled" name="profile_id">
           <?php foreach($profiles as $profile) { ?>
               <option value="<?php echo $profile['profile_id']?>" <?php if ( set_value('profile_id') == $user_details['profile_id']) {?>selected="selected"<? } ?>><?php echo $profile['profile_name']?></option>
           <?php } ?>
      </select>

【问题讨论】:

  • 您在selected="selected"&lt;? } ?&gt;&gt; 中有一个没有php 指示符的php 开始标签,除非您的服务器未设置为识别短标签,否则这不是一个大问题。
  • 是的,这不是问题
  • 如何将以前的用户配置文件显示为默认配置文件类型以及下拉列表中的所有可用配置文件类型

标签: php html forms codeigniter


【解决方案1】:

如果你要使用 Codeigniter 的内置 form_dropdown 很容易

$options    =   array();
foreach($profiles as $profile){
    $options[$profile['id']]    =   $profile['profile_name'];
}
$select =   isset($user_details['profile_id']) ? $user_details['profile_id'] : 0;

form_dropdown('profile_id',$options , $select , 'class= "styled" ');

它需要 4 个参数。第三和第四是可选的。第 3 个是您要选择的键,第 4 个用于其他属性,如 class 、 id 等。第一个是名称,第二个是数组。

有关详细信息,请参阅Form Dropdown 用户指南。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 2018-07-13
    • 1970-01-01
    • 2016-07-10
    • 2015-04-20
    • 2014-02-20
    • 2016-01-06
    相关资源
    最近更新 更多