I want to get the id_user
data based on the desired row table using onclick jquery
, so the already obtained id_user
data can be passed to the controller and direct the page to edit_user
.
How do I get the id_user
data with onclick
using the jquery function? I tried it but what I got 'undefined'.
Sorry for my bad English.
This is my function
function edit(){
var id_user = $(this).attr("id_user");
alert(id_user);
$.ajax({
type:"POST",
url : "<?php echo BASE_URL ?>app.php/usermanagement/edit_user",
data :{id_user:id_user},
success:function(data){
alert(data)
console.log(data)
},
error:function(err){
alert(err)
}
});
}
This my a
tag
<a onclick="edit()" id_user="<? echo $row ['idx']; ?>" href="#" >Edit</a>
This is my code for edit_user form
<form method="POST">
<fieldset>
<legend> Edit User Management </legend>
<table border="0" width="700" id="usermanagement">
<tbody>
<tr>
<td width="160"><strong>Company</strong></td>
<td width="10">:</td>
<td width="193" colspan="2" class="company"><span class ="id_company"><?php echo Session::get('pyrCode'); ?></span> <?php echo $data_from_ctr['account']['desc']['desc'];?></td>
</tr>
<tr class="odd">
<td width="150"><strong>Username</strong></td>
<td width="10">:</td>
<td colspan="2">
<input type="text" name="username" id="username" value="<?php echo $data_from_ctr['user']['_user']; ?>" />
<input type="hidden" name="existing_username" value="<?php echo $data_from_ctr['user']['_user']; ?>"/>
</td>
</tr>
<tr>
<td width="150"><strong>Email</strong></td>
<td width="10">:</td>
<td colspan="2">
<input type="text" name="email" id="email" value="<?php echo $data_from_ctr['user']['email']; ?>" />
</td>
</tr>
<tr class="odd">
<td width="150"><strong>Status User</strong></td>
<td width="10">:</td>
<td colspan="2">
<input type="radio" name="status_active" value="1" <?php if ($data_from_ctr['user']['active'] == 1) { ?> checked="" <? } ?> id="aktif"/>
Active
<input type="radio" name="status_active" value="0" <?php if ($data_from_ctr['user']['active'] == 0) { ?> checked="" <? } ?> id="nonaktif" />
Non Active
</td>
</tr>
<!--<tr class="odd">
<td width="150"><strong>Status User</strong></td>
<td width="10">:</td>
<td colspan="2">
<input type="radio" name="status_active" value="<?php //echo $data_from_ctr['user']['active']; ?>" checked="" id="aktif"/>
Active
<input type="radio" name="status_active" value="<?php //echo $data_from_ctr['user']['active'];?>" id="nonaktif" />
Non Active
</td>
</tr>-->
<tr>
<td width="150"><strong>Name</strong></td>
<td width="10">:</td>
<td colspan="2">
<input type="text" name="name" id="name" value="<?php echo $data_from_ctr['user']['_fullName']; ?>" />
</td>
</tr>
<tr class="odd">
<td width="150"><strong>Phone Number</strong></td>
<td width="10">:</td>
<td colspan="2">
<input type="text" name="phone" id="phone" value="<?php echo $data_from_ctr['user']['_noHP']; ?>" />
</td>
</tr>
<tr>
<td width="150"><strong>Access Control</strong></td>
<td width="10">:</td>
<td colspan="2">
<select id="access" name="access">
<option <?php if ($data_from_ctr['user']['group_user'] == 'user'){ ?> selected="" <? } ?> value="user">User </option>
<option <?php if ($data_from_ctr['user']['group_user'] == 'admin_bank'){ ?> selected="" <? } ?> value="admin_bank">Admin Bank</option>
<option <?php if ($data_from_ctr['user']['group_user'] == 'admin_client'){ ?> selected="" <? } ?> value="admin_client">Admin Client</option>
</select>
</td>
</tr>
<tr <?php if ($data_from_ctr['user']['group_user'] != 'user'){ ?> style= "display: none" <? } ?> class="odd level">
<td width="150"><strong>Level</strong></td>
<td width="10">:</td>
<td colspan="2">
<select id="level" name="level">
<option <?php if($data_from_ctr['user']['_status'] == '01'){ ?> selected="" <? } ?> value="01">Inputer</option>
<option <?php if($data_from_ctr['user']['_status'] == '02'){ ?> selected="" <? } ?> value="02">Verificator</option>
<option <?php if($data_from_ctr['user']['_status'] == '03'){ ?> selected="" <? }?> value="03">Authorize 1</option>
<option <?php if($data_from_ctr['user']['_status'] == '04'){ ?> selected="" <? } ?> value="04">Authorize 2</option>
<option <?php if($data_from_ctr['user']['_status'] == '05'){ ?> selected="" <? } ?> value="05">COPS</option>
</select>
</td>
</tr>
<tr style="display: none" class="limit">
<td width="150"><strong>Limit Transaction</strong></td>
<td width="10">:</td>
<td colspan="2">
<input type="text" name="limit" id="limit value="<?php echo $data_from_ctr['user']['limit']; ?>" />
</td>
</tr>
<tr class="odd">
<td width="150"><strong>Account Access</strong></td>
<td width="10">:</td>
<td colspan="2">
<select id="acctAccessed" name="acctAccessed[]" multiple="multiple" class="chosen-select" style="width:350px;" data-placeholder="Select account">
<?php foreach ($data_from_ctr['account']['account'] as $data) :?>
<option <?php if($data['selected'] == "1"){ ?> selected="" <? } ?>value="<?php echo $data['id'] ?>"><?php echo $data['_giro_OB']; ?></option>
<?php endforeach; ?>
</select>
<input id="chkall" type="checkbox" >Select All</input>
</td>
</tr>
<tr>
<td width="150"> </td>
<td width="10"> </td>
<td colspan="2"><input class="btnsubmitdis" type="submit" value="Save" /></td>
</tr>
</tbody>
</table>
</fieldset>
This is my Controller
public function edit(){
Template::setTitle('Edit User Management');
$id_user =(int)Request::post('id_user');
//$id_user = (int)$_POST['id_user'];
echo $id_user; die;
//$id_user = (int)Session::get('idx');
$result = $this->getUserbyId($id_user);
$dataresult = json_decode($result, true);
if($dataresult === NULL) {
echo "<script language = \"javascript\">window.alert(\No Have Data\");";
echo "javascript:history.back();</script>";
return false;
}
$data = $dataresult;
return $data;