Can't pass data from view to controller - php

I have a strange problem.
I can't pass the data from form to controller. I think my code was right, but I don't know why it can't pass the data- and always says "failed". I've tried to print the data that I post, but it says 'no data'.
Maybe there is something I forgot to do, and can you help me?
Here's my code
view code :
<div id="register" class="text-center">
<div class="container">
<div class="section-title center">
<h2>Register</h2>
<hr>
<form action="<?php echo base_url('c_register/do_insert'); ?>" method="post">
<link href="<?php echo base_url();?>assets/user/css/login.css" rel="stylesheet">
<input type="text" name="firstname" id="firstname" placeholder="First Name">
<span class="text-danger"> <?php echo form_error("firstname"); ?></span>
<input type="text" name="lastname" id="lastname" placeholder="Last Name">
<span class="text-danger"> <?php echo form_error("lasttname"); ?></span>
<input type="text" name="fullname" id="fullname" placeholder="Full Name">
<span class="text-danger"> <?php echo form_error("fullname"); ?></span>
<input type="text" name="username" id="username" placeholder="Username">
<span class="text-danger"> <?php echo form_error("username"); ?></span>
<input type="text" name="email" id="email" placeholder="Email">
<span class="text-danger"> <?php echo form_error("email"); ?></span>
<input type="password" name="pass" id="pass" placeholder="Password">
<span class="text-danger"> <?php echo form_error("pass"); ?></span>
<!-- <input type="password" name="pass1" placeholder="Retype Password"> -->
<ul>
<p1>Gender</p1>
<select name="gender" id="gender" class="pilihan">
<span class="text-danger"> <?php echo form_error("gender"); ?></span>
<option value="men">Male</option>
<option value="women">Female</option></select>
</ul>
<ul>
<p1>Occupation</p1>
<li><input type="radio" name="job" value="doctor" id="doctor" checked> Doctor<br></li>
<span class="text-danger"> <?php echo form_error("job"); ?></span>
<li><input type="radio" name="job" value="nurse" id="nurse"> Nurse<br></li>
</ul>
<link rel="stylesheet" type="text/css" href="assets/user/login.css">
Primary link
</form>
my controller code :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class C_register extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->model('m_register');
}
// function index()
// {
// $this->template->load('static','register');
// }
function do_insert(){
// $this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('firstname', 'firstname', 'required');
$this->form_validation->set_rules('lastname', 'lastname', 'required');
$this->form_validation->set_rules('fullname', 'fullname', 'required');
$this->form_validation->set_rules('username', 'username', 'required');
$this->form_validation->set_rules('email', 'email', 'required');
$this->form_validation->set_rules('pass', 'pass', 'required');
$this->form_validation->set_rules('gender', 'gender', 'required');
$this->form_validation->set_rules('job', 'job', 'required');
if ($this->form_validation->run()) {
//true
$data = array(
'firstname' => $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'),
'fullname' => $this->input->post('fullname'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'pass' => $this->input->post('pass'),
'gender' => $this->input->post('gender'),
'job' => $this->input->post('job')
);
$this->m_register->InsertData($data);
echo "success";
} else {
//false
// $this->index();
echo "failed";
}
}
?>
my model code :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class M_register extends CI_Model {
public function InsertData($data){
$this->db->insert("member", $data);
}
}
?>

With your current implementation, you have hidden any errors you might be getting.
So to see them, quickly, you need to load the form helper and add the line
echo validation_errors();
Just before you run the validation, just so you can see what is going on.
OR you can view the post data by doing a var_dump($_POST); in the same location

Related

How can I persist invalid edit form data in this Codeigniter 3 application?

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.

form data into database using codeigniter

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Model{
function __construct(){
$this->userTbl='login';
}
public function insert($data=array()){
if(!array_key_exists("created", $data)){
$data['created'] = date("Y-m-d H:i:s");
}
if(!array_key_exists("modified", $data)){
$data['modified'] = date("Y-m-d H:i:s");
}
$insert = $this->db->insert($this->userTbl, $data);
if($insert){
return $this->db->insert_id();;
}else{
return false;
}
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Users extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->model('user');
}
/*
* User registration
*/
public function registration(){
$data=array();
$userData=array();
if($this->input->post(regisSubmit)){
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_email_check');
$this->form_validation->set_rules('password', 'password', 'required');
$this->form_validation->set_rules('conf_password', 'confirm password', 'required|matches[password]');
}
$userData=array(
'name'=>strip_tags($this->input->post('name')),
'email'=>strip_tags($this->input->post('email')),
'password'=>strip_tags($this->input->post('password')),
'gender'=>strip_tags($this->input->post('gender')),
'phone'=>strip_tags($this->input->post('phone'))
);
if($this->form_validation->run()==true){
$insert=$this->user->insert($userData);
if($insert){
$this->session->set_userdata('success_msg', 'Your registration was successfully. Please login to your account.');
redirect(users/login);
}
else{
$data['error_msg']='Try again';
}
}
}
$data['user'] = $userData;
//load the view
$this->load->view('users/registration', $data);
}
<!DOCTYPE html>
<html lang="en">
<head>
<link href="<?php echo base_url(); ?>assets/css/style.css" rel='stylesheet' type='text/css' />
</head>
<body>
<div class="container">
<h2>User Registration</h2>
<form action="" method="post">
<div class="form-group">
<input type="text" class="form-control" name="name" placeholder="Name" required="" value="<?php echo !empty($user['name'])?$user['name']:''; ?>">
<?php echo form_error('name','<span class="help-block">','</span>'); ?>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="Email" required="" value="<?php echo !empty($user['email'])?$user['email']:''; ?>">
<?php echo form_error('email','<span class="help-block">','</span>'); ?>
</div>
<div class="form-group">
<input type="text" class="form-control" name="phone" placeholder="Phone" value="<?php echo !empty($user['phone'])?$user['phone']:''; ?>">
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="Password" required="">
<?php echo form_error('password','<span class="help-block">','</span>'); ?>
</div>
<div class="form-group">
<input type="password" class="form-control" name="conf_password" placeholder="Confirm password" required="">
<?php echo form_error('conf_password','<span class="help-block">','</span>'); ?>
</div>
<div class="form-group">
<?php
if(!empty($user['gender']) && $user['gender'] == 'Female'){
$fcheck = 'checked="checked"';
$mcheck = '';
}else{
$mcheck = 'checked="checked"';
$fcheck = '';
}
?>
<div class="radio">
<label>
<input type="radio" name="gender" value="Male" <?php echo $mcheck; ?>>
Male
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="gender" value="Female" <?php echo $fcheck; ?>>
Female
</label>
</div>
</div>
<div class="form-group">
<input type="submit" name="regisSubmit" class="btn-primary" value="Submit"/>
</div>
</form>
<p class="footInfo">Already have an account? Login here</p>
</div>
</body>
</html>
Here in this form I need to insert data into mysql database using codeigniter. but the data is not inserting into the database and also not showing any error. Below is the code for modal, controller and view page. In database.php file, eerything is fine. Here in this, How to debug the code, and what is the error. Thanks in advance.
Define url in routes.php
$route['user/registration'] = 'Users/registration';
also define your project base_url in config/config.php file
use
form action="user/registration"
method="post">
instead of
form action="" method="post">
and view file in
<input type="text" class="form-control" name="name" placeholder="Name" required="" value="<?php echo !empty($user['name'])?$user['name']:''; ?>">
<?php echo form_error('name','<span class="help-block">','</span>'); ?>
change to:
<input type="text" class="form-control" name="name" placeholder="Name" required="" value="<?php echo isset($user['name']) ? $user['name']:''; ?>">
<?php echo form_error('name','<span class="help-block">','</span>'); ?>
You never post anything to your controller. look at this line of your view file.
<form action="" method="post">
Change to :
<form action="<?php echo base_URL(); ?>Users/registration" method="post">

Error in form validation using codeigniter

I am facing a problem in validating the form using Codeigniter. Below is the code I am using in my project.
I have followed all the rules which I have read in the Codeigniter user guide, but I don't know what that issue is; the validation is not happening.
Controller (page.php)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Page extends Front_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('Page_model');
$this->load->helper(array('form', 'url'));
}
public function index()
{
$data['page_title'] = 'Doctors Feedback';
$data['base_url']= $this->uri->segment_array();
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('qualification', 'Qualification', 'required');
$this->form_validation->set_rules('age', 'Age', 'required');
$this->form_validation->set_rules('date', 'Date', 'required');
$this->form_validation->set_rules('residential', 'Residential Address', 'required');
$this->form_validation->set_rules('clinic', 'Clinic Address', 'required');
$this->form_validation->set_rules('email', 'E-mail', 'required');
$this->form_validation->set_rules('mobile', 'Mobile Number', 'required');
$this->form_validation->set_rules('phone', 'Phone Number', 'required');
$this->form_validation->set_rules('comment', 'Comment', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->view('doctors_form', $data);
}
}
}
?>
View (doctors_form.php)
<form>
<div class="col-md-12 form-group">
<label>Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo set_value('name')?>" placeholder="Name">
<span class="text-danger"><?php echo form_error("name");?></span>
</div>
<div class="col-md-6 form-group">
<label>Select Gender</label>
<select class="form-control jcf-hidden" data-jcf="{"wrapNative": false, "wrapNativeOnMobile": false}">
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="col-md-6 form-group">
<label>Qualification</label>
<input type="text" class="form-control" id="qualification" name="qualification" value="<?php echo set_value('qualification')?>" placeholder="Qualification">
<span class="text-danger"><?php echo form_error("qualification");?></span>
</div>
<div class="col-md-6 form-group">
<label>Age</label>
<input type="text" class="form-control" id="age" name="age" value="<?php echo set_value('age')?>" placeholder="Age">
<span class="text-danger"><?php echo form_error("age");?></span>
</div>
<div class="col-md-6 form-group">
<label>Date</label>
<input type="text" class="form-control" id="date" name="date" value="<?php echo set_value('date')?>" placeholder="Date">
<span class="text-danger"><?php echo form_error("date");?></span>
</div>
<div class="col-md-12 form-group">
<label>Residential Address</label>
<textarea rowa="5" class="form-control" id="address" name="residential" placeholder="Residential Address"></textarea>
<span class="text-danger"><?php echo form_error("residential");?></span>
</div>
<div class="col-md-12 form-group">
<label>Clinic Address</label>
<textarea rowa="5" class="form-control" id="address" name="clinic" placeholder="Clinic Address"></textarea>
<span class="text-danger"><?php echo form_error("clinic");?></span>
</div>
<div class="col-md-12 form-group">
<label>Email</label>
<input type="text" class="form-control" id="email" name="email" value="<?php echo set_value('email')?>" placeholder="Email">
<span class="text-danger"><?php echo form_error("email");?></span>
</div>
<div class="col-md-6 form-group">
<label>Mobile</label>
<input type="text" class="form-control" id="mobile" name="mobile" value="<?php echo set_value('mobile')?>" placeholder="Mobile">
<span class="text-danger"><?php echo form_error("mobile");?></span>
</div>
<div class="col-md-6 form-group">
<label>Phone</label>
<input type="text" class="form-control" id="phone" name="phone" value="<?php echo set_value('phone')?>" placeholder="Phone">
<span class="text-danger"><?php echo form_error("phone");?></span>
</div>
<div class="col-md-12 form-group">
<label>Comment</label>
<textarea rowa="5" class="form-control" id="comment" name="comment" placeholder="Comment"></textarea>
<span class="text-danger"><?php echo form_error("comment");?></span>
</div>
<div class="col-md-12 text-right">
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</form>
First of all you should rename the controller name to Page.php (Make first letter capital). Your controller code should look like this:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Page extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('Page_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
}
public function index()
{
if ($_POST)
{
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('qualification', 'Qualification', 'required');
$this->form_validation->set_rules('age', 'Age', 'required');
$this->form_validation->set_rules('date', 'Date', 'required');
$this->form_validation->set_rules('residential', 'Residential Address', 'required');
$this->form_validation->set_rules('clinic', 'Clinic Address', 'required');
$this->form_validation->set_rules('email', 'E-mail', 'required');
$this->form_validation->set_rules('mobile', 'Mobile Number', 'required');
$this->form_validation->set_rules('phone', 'Phone Number', 'required');
$this->form_validation->set_rules('comment', 'Comment', 'required');
if ($this->form_validation->run() == FALSE)
{
$data['page_title'] = 'Doctors Feedback';
$data['base_url'] = $this->uri->segment_array();
$this->view('doctors_form', $data);
}
else
{
$name = $this->input->post('name',TRUE);
$qualification = $this->input->post('qualification',TRUE);
$age = $this->input->post('age',TRUE);
$date = $this->input->post('date',TRUE);
$residential = $this->input->post('residential',TRUE);
$clinic = $this->input->post('clinic',TRUE);
$email = $this->input->post('email',TRUE);
$mobile = $this->input->post('mobile',TRUE);
$phone = $this->input->post('phone',TRUE);
$comment = $this->input->post('comment',TRUE);
$data = array(
'name' => $name ,
'qualification' => $qualification ,
'age' => $age ,
'date' => $date ,
'residential' => $residential ,
'clinic' => $clinic ,
'email' => $email ,
'mobile' => $mobile ,
'phone' => $phone ,
'comment' => $comment ,
);
// Further deal with model using this array
}
}
}
}
In your view, you should use the codeigniter form open and close tag preferably instead of HTML .
<?php echo form_open('Controller_name/function_name'); ?> // equivalent to <form action='url'>
<?php echo form_close(); ?> // equivalent to </form>
In your case you don't have to write the function name in form_open tag. Just write the controller name because index function is loads by default.

Fatal error: Call to undefined function form_open() line 104

I know most of you guys will realize this is a dumb question but I don't have any idea what's wrong with my code. I'm trying to create a contact form that will be sent into the database. But when I try to go to the contact_form_view.php it says Fatal error: Call to undefined function form_open() on Line 104
Here's the form code
<?php $attributes = array("name" => "contactform");
echo form_open("contactform/index", $attributes);?>
<div class="form-group">
<label for="name">Name</label>
<input class="form-control" name="name" placeholder="Your Full Name" type="text" value="<?php echo set_value('name'); ?>" />
<span class="text-danger"><?php echo form_error('name'); ?></span>
</div>
<div class="form-group">
<label for="email">Email ID</label>
<input class="form-control" name="email" placeholder="Email-ID" type="text" value="<?php echo set_value('email'); ?>" />
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
<div class="form-group">
<label for="subject">Subject</label>
<input class="form-control" name="subject" placeholder="Subject" type="text" value="<?php echo set_value('subject'); ?>" />
<span class="text-danger"><?php echo form_error('subject'); ?></span>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" name="message" rows="4" placeholder="Message"><?php echo set_value('message'); ?></textarea>
<span class="text-danger"><?php echo form_error('message'); ?></span>
</div>
<div class="form-group">
<button name="submit" type="submit" class="btn btn-success">Submit</button>
</div>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
Here's the php code
<?php
class contactform extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation'));
$this->load->database();
}
function index()
{
//set validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean|callback_alpha_space_only');
$this->form_validation->set_rules('email', 'Emaid ID', 'trim|required|valid_email');
$this->form_validation->set_rules('subject', 'Subject', 'trim|required|xss_clean');
$this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean');
//run validation on post data
if ($this->form_validation->run() == FALSE)
{ //validation fails
$this->load->view('contact_form_view');
}
else
{
//insert the contact form data into database
$data = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'subject' => $this->input->post('subject'),
'message' => $this->input->post('message')
);
if ($this->db->insert('contacts', $data))
{
// success
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">We received your message! Will get back to you shortly!!!</div>');
redirect('contactform/index');
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Some Error. Please try again later!!!</div>');
redirect('contactform/index');
}
}
}
//custom callback to accept only alphabets and space input
function alpha_space_only($str)
{
if (!preg_match("/^[a-zA-Z ]+$/",$str))
{
$this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
return FALSE;
}
else
{
return TRUE;
}
}
}
?>
if you please try to load form helper in your autoload.php like this
$autoload['helper'] = array('url', 'form');
i think you load the helper in the controller which have the action of your form not the controller that call the form.
so just add the helper to autoload.php and it will work

Bootstrap bugs on codeigniter?

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.

Categories