[eluser]hamzakhan[/eluser]
controller
Code:
class User extends Controller {
function User()
{
parent::Controller();
//// login check
if ($this->session->userdata('logged_in') == FALSE)
{
redirect('admin/Login');
}
//setting the default template
$this->template->set_template('default');
}
function index()
{
// Write to $title
$this->template->write('title', 'Control Pannel - All User');
//loading the catagory model to get list of all catagories.
$this->load->model('admin/model_user');
$data['user'] = $this->model_user->get_all_user();
//view the catagory view with data in content region.
$this->template->write_view('content', 'admin/view_user', $data, TRUE);
//output or render template
$this->template->render();
}
/*
* update user
*/
function Update()
{
//getting user value from url.
$user_id = $this->uri->segment(4);
/* load model to update the user */
$this->load->model('admin/model_user');
$data['user_update'] = $this->model_user->get_update_user($user_id);
// Write to $title
$this->template->write('title', 'Control Pannel - User Update');
$this->template->write_view('content', 'admin/view_user_update', $data, TRUE);
//output or render template
$this->template->render();
}
the above controller when load it show my the list of user in grid which i want.
but
if i want update the user i click on this link like below
Code:
<a >user_id.'">update user</a>
which is also correct and this link redirect with controler name update and user is
like update/12
and it will show me all user values.
here i want to validate the user values and also want to show error.
my validation function is
Code:
function validate()
{
$user_id = $this->input->post('user_id',TRUE);
/*
* form validation
*/
$this->load->library('form_validation');
/*
* set validation rules
*/
$this->form_validation->set_rules('txt_add_username', 'User Name', 'required|trim|alpha_numeric|min_length[6]|callback_check_username');
$this->form_validation->set_rules('txt_add_password', 'Password', 'required|trim');
if ($this->form_validation->run() == FALSE)
{
$this->Update();
}else {
}
}
this funtino is also in user controller.
but i am not getting that how i can redirect or call the funtion to update page if condition is
false.
my update form is
Code:
<p> </p>
<table width="92%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td style="text-decoration: underline; font-size: 14px;"><h1>Change Passowrd</h1></td>
</tr>
</table>
<p> </p>
<?php echo form_open('admin/user/Update'); ?>
<table width="92%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th align="left"><h2><?php echo $username = (!empty( $user_update[0]->user_name))? $user_update[0]->user_name : '' ;?></h2> </th>
</tr>
<tr>
<th> </th>
</tr>
<tr>
<th align="left">Current Password</th>
</tr>
<tr>
<td><input name="txt_current_password"><?php echo form_error('txt_current_password'); ?></td>
</tr>
<tr>
<th> </th>
</tr>
<tr>
<th align="left">New Password</th>
</tr>
<tr>
<td><input name="txt_new_password"><?php echo form_error('txt_new_password'); ?></td>
</tr>
<tr>
<th align="left"> </th>
</tr>
<tr>
<td><input type="submit" value="Update"></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<?php
echo form_close();
?>