• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drop Down List Unable to Pass Value

#1
[eluser]deliriumfolk[/eluser]
How come when I pass my selected option, it always being seen as 0.
Hence does not post the correct value according to what I had selected in the drop down list.
What might be amiss that does not allow my controller to post in the correct value?

Code:
Model
public function set_user(){
                
        $data = array(
        'username' => $this->input->post('username'),
        'password' => $this->input->post('password'),
            'name' => $this->input->post('name'),
            'email' => $this->input->post('email'),
            'title' => $this->input->post('title'),
            'groupId' => $this->input->post('groupId')
        );
        
        return $this->db->insert('user', $data);
    }
Code:
Controller

public function adduser() {
        
        //$this->load->helper('form');
        $this->load->library('form_validation');
        //Get the user group data so it will be available for drop down list selection
        $data['usergroup'] = $this->usergroup_model->get_usergroup();
        
        $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
     $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
        $this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean');
        $this->form_validation->set_rules('title', 'Title', 'trim|required|xss_clean');
        $this->form_validation->set_rules('usergroup', 'User Group', 'required');
        
        $data['title'] = 'CMS Add User';
        
        if($this->form_validation->run() == FALSE)
        {
            //Field validation failed hence user redirected back to add user form
            $this->load->helper(array('form', 'url'));
            $this->load->view('templates/cms/header', $data);
            $this->load->view('cms/adduser', $data);
            $this->load->view('templates/cms/footer');
        }
        else {
            $this->user_model->set_user();
            redirect('cms/listuser', 'refresh');
        }    
    }

Code:
View


<?php echo validation_errors(); ?>
<?php echo form_open('cms/adduser'); ?>

    <?php echo form_label('Username: ', 'username'); ?>
    <input size="24" id="username" name="username" value="<?php echo set_value('username'); ?>"/>
    <br/>
    &lt;?php echo form_label('Password: ', 'password'); ?&gt;
    &lt;input type="password" size="24" id="passowrd" name="password"/&gt;
    <br/>
    &lt;?php echo form_label('Name: ', 'name'); ?&gt;
    &lt;input type="text" size="24" id="name" name="name" value="&lt;?php echo set_value('name'); ?&gt;"/&gt;
    <br/>
    &lt;?php echo form_label('Email: ', 'email'); ?&gt;
    &lt;input type="text" size="24" id="email" name="email" value="&lt;?php echo set_value('email'); ?&gt;"/&gt;
    <br/>
    &lt;?php echo form_label('Job Title: ', 'title'); ?&gt;
    &lt;input type="text" size="24" id="title" name="title" value="&lt;?php echo set_value('title'); ?&gt;"/&gt;
    <br/>
    User Group: <select name="usergroup">
        <option value="" >--Select--</option>
        &lt;?php foreach ($usergroup as $usergroup_item) { ?&gt;
        <option value="&lt;?php echo $usergroup_item['groupId'] ?&gt;">&lt;?php echo $usergroup_item['name'] ?&gt;</option>
        &lt;?php } ?&gt;
    </select>
    <br/>
    &lt;?php echo form_submit('submit', 'Add User'); ?&gt;
&lt;/form&gt;


Messages In This Thread
Drop Down List Unable to Pass Value - by El Forum - 07-04-2012, 09:53 AM
Drop Down List Unable to Pass Value - by El Forum - 07-04-2012, 10:36 AM
Drop Down List Unable to Pass Value - by El Forum - 07-04-2012, 08:33 PM
Drop Down List Unable to Pass Value - by El Forum - 07-04-2012, 08:55 PM
Drop Down List Unable to Pass Value - by El Forum - 07-04-2012, 09:05 PM
Drop Down List Unable to Pass Value - by El Forum - 07-04-2012, 10:18 PM
Drop Down List Unable to Pass Value - by El Forum - 07-04-2012, 10:26 PM
Drop Down List Unable to Pass Value - by El Forum - 07-04-2012, 11:18 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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