• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Select Form Question

#1
On my user form I can select a list of permission groups available.

On my user table there is a column where called permission_group and that has permission group user is in.

The select form on my view can only currently show what permission names are available.

I would like to know how on the select form that can show that users permission_group first. $data['permission'] = $user_info['permission_group'];


PHP Code:
public function edit() {
$data['title'] = "Users";

$data['entry_username'] = "Username";
$data['entry_group'] = "User Group";
$data['entry_email'] = "Email";
$data['entry_img'] = "User Image";
$data['entry_password'] = "Passowrd";
$data['entry_confirm_password'] = "Confirm Passowrd";
$data['entry_status'] = "User Status";

$user_info $this->model_user->get_single_user_info();

$data['username'] = $user_info['username'];

// Gets permission name from user table
$data['permission'] = $user_info['permission_group']; 

// Gets current list of permission names from permission_names table.
$data['permission_names'] = $this->model_user->get_permission_group_names(); 

$data['email'] = $user_info['email'];

$data['status'] = $user_info['status'];

$this->form_validation->set_rules('username''Username''required|callback_hasPermission');
$this->form_validation->set_rules('permission_group''Permission Group');
$this->form_validation->set_rules('password''Password''matches[confirm_password]');
$this->form_validation->set_rules('email''Email''required|is_valid');
$this->form_validation->set_rules('confirm_password''Confirm Password''matches[password]');
$this->form_validation->set_rules('status''Status''required');

if (
$this->form_validation->run($this) == FALSE) {

$this->load->view('template/user/user_update_view'$data);
} else {

redirect('admin/users');

}


View



Quote:<div class="form-group">

        <label class="col-sm-2" for="input-group"><?php echo $entry_group; ?></label>
        <div class="col-sm-10">
        <select name="permission_group" class="form-control">
            <?php foreach ($permission_names as $p_name) { ?> <!-- Shows current permission_names available only -->
                <option value="<?php echo $p_name['group'];?>"><?php echo $p_name['group'];?></option>
            <?php }?>           
        </select>
        </div>
    </div>
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
Why not have their current group selected instead of showing it "first" (I'm assuming you mean list their current group as first option in the select)? CI's form helpers do that for you if you set it up.
Reply

#3
(03-24-2015, 07:51 AM)CroNiX Wrote: Why not have their current group selected instead of showing it "first" (I'm assuming you mean list their current group as first option in the select)? CI's form helpers do that for you if you set it up.

If you have a codeigniter better way of doing it would be good.

But had a coffee break and then

Thought of this


PHP Code:
<div class="form-group">
 
       <label class="col-sm-2" for="input-group"><?php echo $entry_group?></label>
        <div class="col-sm-10">
        <select name="permission_group" class="form-control"> 
            <?php foreach ($permission_names as $permission_name) { ?>
               <?php if ($permission_name['group'] == $permission) { ?>
               <option value="<?php echo $permission_name['group']; ?>" selected="selected"><?php echo $permission_name['group']; ?></option>
               <?php } else { ?>
               <option value="<?php echo $permission_name['group']; ?>"><?php echo $permission_name['group']; ?></option>
                <?php ?>
            <?php ?>
        </select>
        </div>
    </div> 
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#4
http://www.codeigniter.com/user_guide/he...elper.html
See form_dropdown()
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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