[eluser]moriokasan[/eluser]
I am trying to create a multiple selection using checkboxes inside an HTML table. In this case I am trying to assign multiple roles to a selected user. The table displays fine but I don't know how to parse the user selection from the view in order to call the model (eventualy with an array as parameter) to parse and update the table behind.
This is the controller that launches the view:
Code:
function index($id=0)
{
//check session
$this->load->library('Mysession');
if ($this->mysession->isInactive($this)) return;
$this->load->model('users_roles_assignments_model');
$data['records'] = $this->users_roles_assignments_model->select_all_for_user($id);
$data['userid'] = $id;
//reload page
$data['main_content'] = 'users/users_roles_form';
$this->load->view('includes/template',$data);
}
This is the view
Code:
<br><br>
<h1>Selected roles for current user</h1>
<br><br>
<?php echo form_open('users/users_roles/save'); ?>
<table name="roles" id ="roles" border = 1 cellspacing=2 cellpadding=2 width="500">
<tr>
<th align="center">Selected</th>
<th align="center">Role</th>
</tr>
<?php if(isset($records)) : foreach($records as $row) : ?>
<tr>
<td align="center">
<?php if ($row->userid != null): ?>
<input type="checkbox" name=<?php echo "selected".$row->roleid; ?> id=<?php echo "selected".$row->roleid; ?> value="true" />
<?php else: ?>
<input type="checkbox" name=<?php echo "selected".$row->roleid; ?> id=<?php echo "selected".$row->roleid; ?> value="false" />
<?php endif; ?>
</td>
<td>
<?php echo $row->name; ?>
</td>
<tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="2">
No roles are defined
</td>
</tr>
<?php endif; ?>
</table>
<input type="hidden" name="userid" id="userid" value=<?php echo $userid; ?>></input>
<br>
<p>
<input type = "submit" value="Save Changes"/>
</p>
<br>
<?php echo form_close();?>
<br><br>
I appologize if I screw something up because this is my first post on the forum.
Any suggestion is greately appreciated! Thank you all!