• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
combo box

#1
Hello, 

Can anyone help me find the right code to input combo box through model?

I think I should change role input text into some other codes since it is a combo box that I am trying to input into the database.


PHP Code:
'role' => $this->input->post('email'




controllers/cpages.php


PHP Code:
public function addusers() { 
    
        
$data['options'] = array(
            
'administrator' => 'Administrator',
            
'manager'       => 'Manager',
        );

        
$this->Mpages->add_user();
        
        
$this->load->view('addusers'$data); 
        
    } 



views/addusers.php


PHP Code:
<tr>
    <
td>ROLE</td>
    <
td><?php echo form_dropdown('roles'$options'administrator'); ?></td>
</tr> 


models/Mpages.php


PHP Code:
public function add_user()
    {    
            
        $data 
= array(
            'username' => $this->input->post('username'),
            'email' => $this->input->post('email'),
            'password' => $this->input->post('password'),
            'role' => $this->input->post('email')        
        
);        
        
    

" If I looks more intelligence please increase my reputation."
Reply

#2
Maybe read the CodeIgniter Users Guide on the Form Helper form_dropdown()
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(08-09-2016, 06:32 AM)InsiteFX Wrote: Maybe read the CodeIgniter Users Guide on the Form Helper form_dropdown()


Yes, I already read the user guide but do not know how to fix the model.


models/Mpages.php


PHP Code:
public function add_user()
    {    
            
        $data 
= array(
            'username' => $this->input->post('username'),
            'email' => $this->input->post('email'),
            'password' => $this->input->post('password'),
            'role' => $this->input->post('email')        
        
);        
        
    



I should change the role into something else since it is a dropdown box.

PHP Code:
'role' => $this->input->post('email'
" If I looks more intelligence please increase my reputation."
Reply

#4
This is my revision but I still get strange result:

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')        
        );        
        
        return 
$this->db->insert('login'$data);
        
    } 



username            email                   password             role

user                    [email protected]    12345678           <select name="roles"
" If I looks more intelligence please increase my reputation."
Reply

#5
You have not read the docs! Clearly.

http://www.codeigniter.com/user_guide/he...m_dropdown

Why would you put the output of form_dropdown function into an array with input posts that you then insert into your database!!!!!

I seriously do not know whether to laugh or cry!

This will tell you how dropdowns work
http://www.html-form-guide.com/php-form/...elect.html

Now you have a post field with your dropdown option value. Access it just like you would any other input post. The form helper just helps you to write your select HTML a bit more easily than writing it all out.

Did you say you were building an eCommerce CMS? OMFG :-(
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.