• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recording drop down box on model

#1
Hello,


A PHP Error was encountered
Severity: Notice
Message: Undefined variable: options
Filename: models/Mpages.php
Line Number: 273
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\models\Mpages.php
Line: 273
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\controllers\Cpages.php
Line: 525
Function: add_user
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\companygiondaci\index.php
Line: 315
Function: require_once



models/Mpages.php


PHP Code:
Line 273 'role' => form_dropdown('roles'$options'administrator')        



controllers/cpages.php

PHP Code:
public function addusers() { 
    
        
$data['successmessage'] = "";
    
        
$data['options'] = array(
            
'administrator' => 'Administrator',
            
'manager'       => 'Manager',
        );
        
        
$this->load->view('addusers'$data); 
        
    }

    
public function 
addusersdb() {
        
        
$this->form_validation->set_rules('username''Username''required');
        
$this->form_validation->set_rules('email''Email''required');
                
        
$data['successmessage'] = 'Success Message has been added!';        
        
        
$data['options'] = array(
            
'administrator' => 'Administrator',
            
'manager'       => 'Manager',
        );
        
        if(
$this->form_validation->run() === FALSE)
        {
            
            
$this->load->view('addusers');
            
 
          
        
}
        else
        {
            
            
$this->Mpages->add_user();
            
$this->load->view('addusers'$data);
             
        }    
    
    
    } 


views/addusers.php


PHP Code:
<div class="row-fluid">
                <div class="span12">
                    
                    
<?php $this->load->library('form_validation'); ?>
                    
                    <?php echo $successmessage?>
                        
                    <?php echo validation_errors(); ?>
                        
                    <?php echo form_open('cpages/addusersdb'); ?>
                    
                    <div class="widget-box">
                        <div class="widget-title"><h5>Add User</h5></div>
                        <div class="widget-content">
                        
                        <table border="0" style="width: 100%; height: 90px;">
                            <tr>
                                <td>USERNAME</td>
                                <td><input type="text" name="username"></td>
                            </tr>
                            <tr>
                                <td>EMAIL</td>
                                <td><input type="text" name="email"></td>
                            </tr>
                            <tr>
                                <td>PASSWORD</td>
                                <td><input type="password" name="password"></td>
                            </tr>
                            <tr>
                                <td>ROLE</td>
                                <td><?php echo form_dropdown('roles'$options'administrator'); ?></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><input type="submit" class="edit" value="ADD"></td>
                            </tr>                            
                        </table>            
                        </div>
                    </div>                    
                </div>
            </div> 


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



1)  How to by pass the $option to the model so that it could read what is $option ?

2)  After I press submit button then the next textbox turns small instead of big like the previous one.  Why is it ?  And how to control the textbox so that it remains on the same size even after I press the submit button ?
" If I looks more intelligence please increase my reputation."
Reply

#2
And what does undefined variable mean?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
I thought this is the definition:

 
PHP Code:
$data['options'] = array(
            'administrator' => 'Administrator',
            'manager'       => 'Manager',
        );
        
        
if($this->form_validation->run() === FALSE)
        {
            
            $this
->load->view('addusers');
            
           
        
}
        else
        {
            
            $this
->Mpages->add_user();
            $this->load->view('addusers'$data);
             
        
}    
" If I looks more intelligence please increase my reputation."
Reply

#4
@Davy_yg, you don't have any idea what the form_dropdown function is for, do you?
Reply

#5
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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