Welcome Guest, Not a member yet? Register   Sign In
logic help
#1

[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>&nbsp;</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>&nbsp;</p>      
       &lt;?php echo form_open('admin/user/Update'); ?&gt;
        <table width="92%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <th align="left"><h2>&lt;?php echo $username = (!empty( $user_update[0]->user_name))? $user_update[0]->user_name : '' ;?&gt;</h2> </th>
        </tr>
        <tr>
          <th>&nbsp;</th>
        </tr>      
        <tr>
          <th align="left">Current Password</th>
        </tr>
        <tr>
          <td>&lt;input name="txt_current_password"&gt;&lt;?php echo form_error('txt_current_password'); ?&gt;</td>
        </tr>
        <tr>
          <th>&nbsp;</th>
        </tr>  
        <tr>
          <th align="left">New Password</th>
        </tr>
        <tr>
          <td>&lt;input name="txt_new_password"&gt;&lt;?php echo form_error('txt_new_password'); ?&gt;</td>
        </tr>    
        <tr>
          <th align="left">&nbsp;</th>
        </tr>    
        <tr>
          <td>&lt;input type="submit" value="Update"&gt;&lt;/td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
      
      &lt;?php
              echo form_close();
      ?&gt;
#2

[eluser]theprodigy[/eluser]
try changing your form action to validate rather than Update.

Change:
Code:
&lt;?php echo form_open('admin/user/Update'); ?&gt;
To:
Code:
&lt;?php echo form_open('admin/user/validate'); ?&gt;
#3

[eluser]hamzakhan[/eluser]
but its not my problem my frnd.
#4

[eluser]jedd[/eluser]
[quote author="hamzakhan" date="1260466279"]but its not my problem my frnd.[/quote]

Because your original post had no question marks in it - it's hard to identify your actual problem.

Have a read of [url="http://codeigniter.com/wiki/How_to_ask_a_good_question/"]this guide to asking sensible questions[/url].

What you could do to make it easier to help you is rather than dump a lot of code, interspersed with observations about what the code is doing - just describe what you are trying to do, what you expect to happen, and what actually does happen.

That is: intent, expectation, deviation.




Theme © iAndrew 2016 - Forum software by © MyBB