I have the form_validation library loaded in my controller and the form validation itself is working, but when using set_value() it's not populating the form fields. Here is the code in to controller:
function addUser()
{
$this->form_validation->set_rules('firstName', 'firstname', 'trim|required|max_length[30]');
$this->form_validation->set_rules('surname', 'surname', 'trim|required|max_length[30]');
$this->form_validation->set_rules('emailAddress', 'email address', 'trim|required|valid_email|is_unique[users.email]|max_length[255]');
$this->form_validation->set_rules('password', 'password', 'trim|required|max_length[20]|min_length[5]');
$this->form_validation->set_rules('passwordVerify', 'password verification', 'trim|required|max_length[20]|min_length[5]');
if($this->form_validation->run() === FALSE) {
$this->session->set_flashdata('formValidationError', validation_errors('<p class="error">', '</p>'));
redirect('/member/register');
} else {
echo 'Passed';
}
}
And here is the code in the view:
<?php echo $this->session->flashdata('formValidationError'); ?>
<form method="POST" action="<?php echo site_url('member/addUser'); ?>">
<fieldset>
<legend>Create a FREE account</legend>
<div>
<label for="firstName">Firstname</label>
<input type="text" name="firstName" value="<?php echo set_value('firstName'); ?>" maxlength="30">
</div>
<div>
<label for="surname">Surname</label>
<input type="text" name="surname" value="<?php echo set_value('surname'); ?>" maxlength="30">
</div>
<div>
<label for="emailAddress">Email Address</label>
<input type="text" name="emailAddress" value="<?php echo set_value('emailAddress'); ?>" maxlength="255">
</div>
<div>
<label for="password">Password</label>
<input type="password" name="password" maxlength="20">
</div>
<div>
<label for="passwordVerify">Verify Password</label>
<input type="password" name="passwordVerify" maxlength="20">
</div>
<button type="submit">Register</button>
</fieldset>
</form>
Is there something I am missing? Is the redirect causing the issue?
It is not working because you are using redirection.
Instead of
$this->session->set_flashdata('formValidationError', validation_errors('<p class="error">', '</p>'));
redirect('/member/register');
just for testing, try to load the view
$this->load->view('member_register_view');
and you will see.
set_value requires that the form validation ran in the same context... you lose this context when you redirect.
i had the same issue with redirect(), i used $this->session->set_flashdata('field','value') to store data before redirect, as loading view was not possible in my case, and reused it as value of input tag,
<input type='text' value='<?= $this->session->flashdata('field') ?>' >
Related
I am working on a basic blog application with Codeigniter 3.1.8 and Bootstrap 4.
There is, among others an "Edit account information" form:
<?php echo form_open(base_url('dashboard/users/update')); ?>
<input type="hidden" name="id" id="uid" value="<?php echo $author->id; ?>">
<div class="form-group <?php if(form_error('first_name')) echo 'has-error';?>">
<input type="text" name="first_name" id="first_name" class="form-control" value="<?php echo $author->first_name;?>" placeholder="First name">
<?php if(form_error('first_name')) echo form_error('first_name'); ?>
</div>
<div class="form-group <?php if(form_error('last_name')) echo 'has-error';?>">
<input type="text" name="last_name" id="last_name" class="form-control" value="<?php echo $author->last_name;?>" placeholder="Last name">
<?php if(form_error('last_name')) echo form_error('last_name'); ?>
</div>
<div class="form-group <?php if(form_error('email')) echo 'has-error';?>">
<input type="text" name="email" id="email" class="form-control" value="<?php echo $author->email;?>" placeholder="Email">
<?php if(form_error('email')) echo form_error('email'); ?>
</div>
<div class="form-group <?php if(form_error('bio')) echo 'has-error';?>">
<textarea name="bio" id="bio" cols="30" rows="5" class="form-control" placeholder="Add a short bio"><?php echo $author->bio; ?></textarea>
<?php if(form_error('bio')) echo form_error('bio'); ?>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-block btn-md btn-success">
</div>
<?php echo form_close(); ?>
It's corresponding controller logic is this:
public function edit($id) {
// Only logged in users can edit user profiles
if (!$this->session->userdata('is_logged_in')) {
redirect('login');
}
$data = $this->Static_model->get_static_data();
$data['pages'] = $this->Pages_model->get_pages();
$data['categories'] = $this->Categories_model->get_categories();
$data['author'] = $this->Usermodel->editAuthor($id);
$this->load->view('partials/header', $data);
$this->load->view('dashboard/edit-author');
$this->load->view('partials/footer');
}
public function update() {
// Only logged in users can edit user profiles
if (!$this->session->userdata('is_logged_in')) {
redirect('login');
}
$id = $this->input->post('id');
$data = $this->Static_model->get_static_data();
$data['pages'] = $this->Pages_model->get_pages();
$data['categories'] = $this->Categories_model->get_categories();
$data['author'] = $this->Usermodel->editAuthor($id);
$this->form_validation->set_rules('first_name', 'First name', 'required');
$this->form_validation->set_rules('last_name', 'Last name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
$this->form_validation->set_error_delimiters('<p class="error-message">', '</p>');
if($this->form_validation->run() === FALSE)
{
$this->load->view('partials/header', $data);
$this->load->view('dashboard/edit-author');
$this->load->view('partials/footer');
} else
{
$this->Usermodel->update_user($id);
$this->session->set_flashdata('user_updated', 'Your account details have been updated');
redirect(base_url('/dashboard/manage-authors'));
}
}
The problem I have not been able to solve is related to the validation of this form: if I leave a required filed empty, and try to submit the form, the form is loaded, with the proper validation error message, only the invalid field is populated with the data from the database and so, valid data is displayed along with the error message, as seen in the form below:
However, as long as the field's current value is not replaced with an invalid one, I want it (the field value) to come from the database.
How can I solve this issue?
If you want to keep the submitted data on an input value, you could modify the email codes like this :
<div class="form-group <?php if(form_error('email')) echo 'has-error';?>">
<input type="text" name="email" id="email" class="form-control" value="<?php echo set_value('email', $author->email); ?>" placeholder="Email">
<?php if(form_error('email')) echo form_error('email'); ?>
</div>
This will set the submitted data as the email value (if available), or email data from the database if there is no submitted email data.
What i am trying to do is:
post a form when user is logged in.
but if he is not logged in then pop up login is shown to user.
and in that popup redirection URL is added to hidden field.
when popup opens and i login it redirect me to that form.
But when i try to submit form it not being submitted.
// submit button in form
$('#submitcompanyEnquiry').on('click',function(e){
e.preventDefault();
//get data attr to check if user is login
if($('#companyEnquiry').data('login')){
//companyEnquiry =>form id
//here i try to submit form
console.log('testing'); --->it is working
jQuery('#companyEnquiry').submit(); ---> //the problem is here this piece of code is executing
}else{
if($('#companyEnquiry').attr('action')!=''){
//here i added the current url to hidden field latter to used for redirection
$('#loginForm #redirectUrl').val($('#companyEnquiry').data('seotitle'));
}
//here the login popup is trigger.
jQuery("#login").trigger('click');
}
});
Things that I confirmed:
ensure that there is unique id with the
name provided.
console some value in the if block which was
running but the line of code i have mention.
PHP part is working fine i have removed the e.preventDefault();
it is works fine but doesn't achieve the require functionality.
HTML Code
<form action="<?=Route::url('default',array('controller'=>'contact','action'=>'user_contact'))?>" data-login="<?php echo $data; ?>" data-seotitle="<?=Route::url('company', array('controller'=>'listing','seotitle'=>$company_seotitle))?>" id="companyEnquiry" method="post">
<input type="hidden" name="company_to" value="<?php echo $id; ?>">
<?php if (!$auth->logged_in()) { ?>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="Name" name="name" required aria-describedby="basic-addon1">
</div>
<?php }else { ?>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="Name" required value="<?php echo $auth->get_user()->company_name; ?>" name="name" aria-describedby="basic-addon1">
</div>
<?php } ?>
<?php if (!$auth->logged_in()) { ?>
<div class="input-group searchbox">
<input type="email" class="form-control search" placeholder="email" required name="company_from" aria-describedby="basic-addon1">
</div>
<?php }else { ?>
<div class="input-group searchbox">
<input type="email" class="form-control search" placeholder="email" required value="<?php echo $auth->get_user()->companyemail; ?>" name="company_from" aria-describedby="basic-addon1">
</div>
<?php } ?>
<?php if ($auth->logged_in()) { ?>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="phone number" required name="phone" value="<?php echo $auth->get_user()->company_phone_1; ?>" aria-describedby="basic-addon1">
</div>
<?php } else { ?>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="phone number" required name="phone" aria-describedby="basic-addon1">
</div>
<?php } ?>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="subject" required name="subject" aria-describedby="basic-addon1">
</div>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="message" required name="message" aria-describedby="basic-addon1">
</div>
<input data-login="<?php echo $data; ?>" id="submitcompanyEnquiry" type="submit" name="submit" value="SEND" class="form-control blue-btn send-btn">
</form>
The problem can only exist in the way you are adding the login variable to the form with the id : companyEnquiry
Check if you have add it as correct parameter because jquerys data function will only read values which have a "data-" tag infront of it.
So your php code should look like this :
echo '<form id="companyEnquiry" ' . ($login ? 'data-login="1"' : '' . '>
I need to validate a user form, which I am trying to submit after taking the input in view named as 'home.php', where I have specified the base_url('Home/user_validation').
With Home is name of the controller and user_validation is the method name. I tried to figure out the issue but I could not understand why not any other function is being invoked apart from index function in Home controller. Please help me in this case.
Controller Home.php
public function user_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required');
$this->form_validation->set_rules('password', 'Password', 'trim|required');
if ($this->form_validation->run() == FALSE) {
$this->session->set_flashdata('message', 'Invalid username and password.');
redirect('home');
}
else {
$user_name123 = $this->input->post('username');
$teacher = $this->input->post('remember');
if ($user_name123 == 'admin') {
$query = $this->login_model->validate();
echo("Logged in");
}
}
}
Model login_model.php
function validate()
{
$this->db->where('admin_username', $this->input->post('username'));
$this->db->where('admin_password', $this->input->post('password'));
$this->db->where('active_status', 'Yes');
$query = $this->db->get('cis_tbl_admin');
if ($query->num_rows() == 1) {
return true;
}
else {
return false;
}
}
View home.php
<form action="<?php echo base_url('Home/user_validation') ?>" method="post" id="instantform">
<fieldset>
<div class="input-prepend" title="Username" data-rel="tooltip">
<span class="add-on"><i class="icon-user"></i></span>
<input autofocus class="input-large span10"
name="username" id="username" type="text"
placeholder="user name"/>
</div>
<div class="clearfix"></div>
<div class="input-prepend" title="Password" data-rel="tooltip">
<span class="add-on"><i class="icon-lock"></i></span>
<input class="input-large span10" name="password"
id="password" type="password"
placeholder="password" autocomplete="off"/>
</div>
<div class="clearfix"></div>
<div class="input-prepend">
<label class="remember" for="remember">
<input type="checkbox" name="remember" id="remember"
value="teacher"/>Teacher Login</label>
</div>
<div class="clearfix"></div>
<p class="center span5">
<button type="submit" name="submit" id="submit" class="btn btn-primary">Login</button>
<br/><br/>
<!--<a class="ajax-link" href="<?php echo base_url(); ?>parent_info/get_students_info"> <span class="hidden-tablet">Parent Login</span></a>-->
</p>
</fieldset>
<input type="hidden" name="sys_date" id="sys_date" value="<?php echo $sys_date; ?>">
<input type="hidden" name="sys_time" id="sys_time" value="<?php echo $sys_time; ?>">
<input type="hidden" name="details" id="details" value="<?php echo $details; ?>">
</form>
Check your config routes file to be sure you call functions of the home controller:
$route['Home/(:any)'] = 'Home/$1';
I have a dynamic form that is generated depending on how many people are selected from another page. When I submit this form however, the form validation fails without giving me an error. Could someone take a look and see why it's failing? I have tried debugging it but I can't see it. Maybe my method is wrong? This form used to work as well. It started to not work after I added the form processing for the children. Hopefully someone can help. Thank you so much.
Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Details extends TX_Controller {
public function __construct(){
parent::__construct();
ini_set('memory_limit', '64M');
$this->load->model('TransactionsModel');
$this->load->model('ProductsModel');
}
public function index(){
$data['productdetail'] = $this->ProductsModel->getProduct($this->session->userdata('productid'));
// var_dump($data['productdetail']);
$data['adults'] = $this->session->userdata('adults');
$data['children'] = $this->session->userdata('children');
$this->load->view('public/publicMenu/navigationLink');
$this->load->view('public/publicDetails/details',$data);
$this->load->view('public/publicMenu/navigationJquery');
}
public function next(){
$adultlength = $this->input->post('adults');
$childrenlength = $this->input->post('children');
$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
for ($i=0; $i < $adultlength; $i++) {
$this->form_validation->set_rules('inputfirstname['.$i.']', 'Firstname', 'trim|required');
$this->form_validation->set_rules('inputlastname['.$i.']', 'Lastname', 'trim|required');
$this->form_validation->set_rules('inputdateofbirth['.$i.']', 'Date of Birth', 'trim|required');
$this->form_validation->set_rules('inputicnumber['.$i.']', 'IC Number', 'trim|required');
$this->form_validation->set_rules('inputmobilenumber['.$i.']', 'Mobile Number', 'trim|required');
$this->form_validation->set_rules('inputemail['.$i.']', 'Email', 'trim|required');
$this->form_validation->set_rules('inputconfirmemail['.$i.']', 'Confirm Email', 'trim|required');
$inputfirstname[] = $this->input->post('inputfirstname['.$i.']');
$inputlastname[] = $this->input->post('inputlastname['.$i.']');
$inputdateofbirth[] = $this->input->post('inputdateofbirth['.$i.']');
$inputicnumber[] = $this->input->post('inputicnumber['.$i.']');
$inputmobilenumber[] = $this->input->post('inputmobilenumber['.$i.']');
$inputemail[] = $this->input->post('inputemail['.$i.']');
$inputpostcode[] = $this->input->post('inputpostcode['.$i.']');
}
for($j=0;$j<$childrenlength;$j++){
$inputchildfirstname[] = $this->input->post('inputchildfirstname['.$j.']');
$inputchildlastname[] = $this->input->post('inputchildlastname['.$j.']');
$inputchilddateofbirth[] = $this->input->post('inputchilddateofbirth['.$j.']');
}
if($this->form_validation->run()==false){
$data['productdetail'] = $this->ProductsModel->getProduct($this->session->userdata('productid'));
$data['adults'] = $this->session->userdata('adults');
$data['children'] = $this->session->userdata('children');
$this->load->view('public/publicMenu/navigationLink');
$this->load->view('public/publicDetails/details',$data);
$this->load->view('public/publicMenu/navigationJquery');
}else{
for ($i=0; $i < $adultlength; $i++) {
$passengerdetails[] = array(
'firstname'=>$inputfirstname[$i],
'lastname'=>$inputlastname[$i],
'dateofbirth'=>$inputdateofbirth[$i],
'icnumber'=>$inputicnumber[$i],
'mobilenumber'=>$inputmobilenumber[$i],
'email'=>$inputemail[$i],
'postcode'=>$inputpostcode[$i],
'usertype'=>'adult'
);
}
if($childrenlength>0){
for($j=0;$j<$childrenlength;$j++){
$childpassengerdetails[] = array(
'firstname'=>$inputchildfirstname[$j],
'lastname'=>$inputchildlastname[$j],
'dateofbirth'=>$inputchilddateofbirth[$j],
'icnumber'=>'',
'mobilenumber'=>'',
'email'=>'',
'postcode'=>'',
'usertype'=>'child'
);
}
$this->session->set_userdata('childpassengerdetails',json_encode($childpassengerdetails));
}
$this->session->set_userdata('passengerdetails',json_encode($passengerdetails));
redirect('/Public/Payment');
}
}
}
View
<section id="about" class="container content-section text-center">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h2><?php echo $productdetail->name;?></h2>
<h2>Enter Passenger Details</h2>
<?php echo form_open_multipart('Public/Details/next','class="inputform"');?>
<h3>Adults</h3>
<?php for($i=0;$i<$adults;$i++){?>
<input type="hidden" class="form-control" name="adult" value="<?php echo $adults;?>">
<label for="inputfirstname">Firstname</label>
<input type="text" class="form-control" name="inputfirstname[]" placeholder="Firstname" value="<?php echo set_value('inputfirstname['.$i.'],""');?>">
<div class="errormessage"><?php echo form_error('inputfirstname['.$i.']'); ?></div>
<label for="inputfirstname">Lastname</label>
<input type="text" class="form-control" name="inputlastname[]" placeholder="Lastname" value="<?php echo set_value('inputlastname[$i]');?>">
<div class="errormessage"><?php echo form_error('inputlastname['.$i.']'); ?></div>
<label for="inputdateofbirth">Date of Birth</label>
<input type="date" class="form-control" name="inputdateofbirth[]" value="<?php echo set_value('inputdateofbirth[$i]');?>">
<div class="errormessage"><?php echo form_error('inputdateofbirth['.$i.']'); ?></div>
<label for="inputicnumber">IC Number</label>
<input type="text" class="form-control" name="inputicnumber[]" placeholder="IC Number" value="<?php echo set_value('inputicnumber[$i]');?>">
<div class="errormessage"><?php echo form_error('inputicnumber['.$i.']'); ?></div>
<label for="inputmobilenumber">Mobile Number</label>
<input type="text" class="form-control" name="inputmobilenumber[]" placeholder="Mobile Number" value="<?php echo set_value('inputmobilenumber[$i]');?>">
<div class="errormessage"><?php echo form_error('inputmobilenumber['.$i.']'); ?></div>
<label for="inputemail">Email</label>
<input type="text" class="form-control" name="inputemail[]" placeholder="Email" value="<?php echo set_value('inputemail[$i]');?>">
<div class="errormessage"><?php echo form_error('inputemail['.$i.']'); ?></div>
<label for="inputconfirmemail">Confirm Email</label>
<input type="text" class="form-control" name="inputconfirmemail[]" placeholder="Confirm Email" value="<?php echo set_value('inputconfirmemail[$i]');?>">
<div class="errormessage"><?php echo form_error('inputconfirmemail['.$i.']'); ?></div>
<label for="inputaddress1">Address</label>
<input type="text" class="form-control" name="inputaddress1[]" placeholder="Address 1" value="<?php echo set_value('inputaddress1[$i]');?>">
<input type="text" class="form-control" name="inputaddress2[]" placeholder="Address 2" value="<?php echo set_value('inputaddress2[$i]');?>">
<input type="text" class="form-control" name="inputaddress3[]" placeholder="Address 3" value="<?php echo set_value('inputaddress3[$i]');?>">
<input type="text" class="form-control" name="inputaddress4[]" placeholder="Address 4" value="<?php echo set_value('inputaddress4[$i]');?>">
<input type="text" class="form-control" name="inputaddress5[]" placeholder="Address 5" value="<?php echo set_value('inputaddress5[$i]');?>">
<label for="inputpostcode">Postcode</label>
<input type="text" class="form-control" name="inputpostcode[]" placeholder="Postcode1" value="<?php echo set_value('inputpostcode[$i]');?>">
<div class="errormessage"><?php echo form_error('inputpostcode['.$i.']'); ?></div>
<?php } ?>
<?php if($children>0){ ?>
<h3>Children</h3>
<?php for($j=0;$j<$children;$j++){ ?>
<input type="hidden" class="form-control" name="children" value="<?php echo $children;?>">
<label for="inputchildfirstname">Firstname</label>
<input type="text" class="form-control" name="inputchildfirstname[]" value="<?php echo set_value('inputchildfirstname[$j]');?>" placeholder="Firstname">
<label for="inputchildlastname">Lastname</label>
<input type="text" class="form-control" name="inputchildlastname[]" value="<?php echo set_value('inputchildlastname[$j]');?>" placeholder="Lastname">
<label for="inputchilddateofbirth">Date of Birth</label>
<input type="date" class="form-control" name="inputchilddateofbirth[]" value="<?php echo set_value('inputchilddateofbirth[$j]');?>">
<?php }} ?>
<p><button type="submit" class="btn btn-primary">Next</button></p>
<p>Cancel</p>
<?php echo form_close(); ?>
<p><?php echo $this->session->flashdata('Form'); ?></p>
</div>
</div>
</section>
perhaps the video will easily explain the problem. here's the link to my video .
here's the view code
<div class="col-sm-4">
<?php echo form_open('user/updateuser');
?>
<legend>Update User</legend>
<div class="form-group">
<label for="id">ID</label>
<input name="id" type="text" class="form-control" id="id" placeholder="Input id" value="<?php echo $id; ?>" disabled>
<?php echo form_error('id'); ?>
</div>
<div class="form-group">
<label for="username">Username</label>
<input name="username" type="input" class="form-control" id="username" placeholder="Input Username" value="<?php echo $username;?>">
<?php echo form_error('username'); ?>
</div>
<div class="form-group">
<label for="password">Old Password:</label>
<input name="old_password" type="password" class="form-control" id="password" placeholder="Input Old Password"" value ="<?php set_value('old_password');?>">
<?php echo form_error('old_password')?>
</div>
<div class="form-group">
<label for="password">New Password:</label>
<input name="password" type="password" class="form-control" id="password" placeholder="Input Password" ">
<?php echo form_error('password')?>
</div>
<div class="form-group">
<label for="password">New Password Confirmation:</label>
<input name="password_conf" type="password" class="form-control" id="password" placeholder="Input Password Confirmation">
<?php echo form_error('password_conf')?>
</div>
<div class="form-group">
<label for="email">Email address</label>
<input name="email" type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" value="<?php echo $email; ?>">
<?php echo form_error('email')?>
</div>
<div class="form-group" align="center">
<button type="submit" class="btn btn-success">Submit</button>
<button type="reset" class="btn btn-danger">Clear</button>
</div>
</div>
<?php
echo form_close();
?>
and here's the controller user/updateuser
function index()
{
//This method will have the credentials validation
$this->form_validation->set_error_delimiters('<div class="alert alert-danger" role="alert">', '</div>');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('old_password', 'Old Password', 'trim|required|xss_clean|callback_check_password');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|matches[password_conf]');
$this->form_validation->set_rules('password_conf', 'Password Confirmation', 'trim|required|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean');
if($this->isloggedin('logged_in'))
{
if($this->form_validation->run() == FALSE)
{
$data = array(
'sess_username' => $this->isloggedin('logged_in'),
'id' => $this->input->post('id'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email')
);
$this->load->view('header');
$this->load->view('main/menu_super_admin',$data);
$this->load->view('user/modifuser');
$this->load->view('footer');
}
else
{
$query = $this->m_user->updateuser($this->input->post('id'),$this->input->post('username'),md5($this->input->post('password')),$this->input->post('email'));
if($query)
{
echo "<script>window.onload = function() { return alert(\" Update User Success ! \"); }</script>";
}
else
{
return false;
}
redirect('user/user', 'refresh');
}
}
else
{
redirect('login', 'refresh');
}
}
the problem is, i want to make the disabled input stay disabled and the values remains the same,
is there any mistakes on my code ?
Disabled inputs are not posted to the server: http://www.w3.org/TR/html401/interact/forms.html#disabled
... [a disabled input] cannot receive user input nor will its value be submitted with the form.
I suggest getting the ID from the session and not relying on the posted information in any way (This is a security concern because posted information can be manipulated by the end user). You already check to see if the user is logged in. Just get the ID from the the session while you're at it.
Session ID can be retrieved like so:
$data = array(
'sess_username' => $this->isloggedin('logged_in'),
'id' => $this->session->userdata('session_id'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email')
);
You may also need to load the library first
$this->load->library('session');
I also suggest using sess_use_database as mentioned in the docs for added session security.