Recording drop down box on model - davy_yg - 08-30-2016
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 ?
RE: Recording drop down box on model - InsiteFX - 08-30-2016
And what does undefined variable mean?
RE: Recording drop down box on model - davy_yg - 08-30-2016
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); }
RE: Recording drop down box on model - Wouter60 - 08-30-2016
@davy_yg, you don't have any idea what the form_dropdown function is for, do you?
RE: Recording drop down box on model - wolfgang1983 - 08-30-2016
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/libraries/form_validation.html#prepping-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')
|