Welcome Guest, Not a member yet? Register   Sign In
Recording drop down box on model
#5

(This post was last modified: 08-30-2016, 03:49 PM by wolfgang1983.)

In your model if form false I would run data again and only use two equal  ==  and don't for get to set_rules http://www.codeigniter.com/user_guide/li...pping-data


PHP Code:
function something() {

    $data['options'] = array(
        'administrator' => 'Administrator',
        'manager'=> 'Manager',
    );
 
    
$this->form_validation->set_rules('roles''Roles''trim');
            
    if 
($this->form_validation->run() == FALSE) {
                
      $this
->load->view('addusers'$data); // If false Run Data            
               
    
} else {
                
        $this
->mpages->add_user();
        $this->load->view('addusers'$data);
                 
    
}    



Another controller way is this


PHP Code:
function something() {

  $this->form_validation->set_rules('roles''Roles''trim');
            
    if 
($this->form_validation->run() == true) {
                
      $this
->mpages->add_user();
      redirect('successpage');          
               
    


    $data['options'] = array(
        'administrator' => 'Administrator',
        'manager'=> 'Manager',
    );
              
        
    $this
->load->view('addusers'$data);



Model


PHP Code:
public function add_user() {    
            
    $data 
= array(
        'username' => $this->input->post('username'),
        'email' => $this->input->post('email'),
        'password' => $this->input->post('password'),
        // 'role' => form_dropdown('roles', $options, 'administrator') form dropdown is for view
        'role' => $this->input->post('roles')   
    
);        
        
    $this
->db->insert('login'$data);
        



On view


Code:
form_dropdown('roles', $options, 'administrator')
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
Recording drop down box on model - by davy_yg - 08-30-2016, 03:14 AM
RE: Recording drop down box on model - by davy_yg - 08-30-2016, 04:44 AM
RE: Recording drop down box on model - by wolfgang1983 - 08-30-2016, 02:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB