Welcome Guest, Not a member yet? Register   Sign In
Two form
#1

[eluser]Unknown[/eluser]
Hi, I want to make a continuation of two forms for users. The first one is reserved to enter all them informations. When he submit this one, he arrived on a second form on which he can see all the informations he has put in the previews one and modify it if he made an error. The problem is : when i submit the second one, a new user is created in my db.
This is my controller:
Code:
class User extends CI_Controller
{

public function __construct(){
  parent::__construct();
  $this->load->model('user_model', 'userManager');
}

public function index(){  
  //$data['img_captcha'] = $this->_create_captcha();
  //$this->load->view('index'/*, $data*/);
  $this->set_user();
}

public function set_user(){
  
  $id_user = md5(uniqid().time());
  $this->form_validation->set_error_delimiters('<p class="form_erreur">', '</p>');
  
  $this->form_validation->set_rules('name', 'Name', 'trim|required|alpha|xss_clean|htmlenties');
  $this->form_validation->set_rules('father_name', 'Father name', 'trim|required|alpha|xss_clean|htmlentities');
  $this->form_validation->set_rules('num_passeport', 'Passport numero', 'trim|required|alpha_numeric|xss_clean|htmlentities');
$this->form_validation->set_rules('captcha', 'Security Code', 'trim|required|callback_check_captcha');
if($this->form_validation->run() && $this->input->post('valider')){
   $this->userManager->ajouter_user($id_user,
                                                                       $this->input->post('name'),
                                                                             $this->input->post('father_name'));
$this->load->view('confirmation', $data);
}else {
   $data['img_captcha'] = $this->_create_captcha();
   $this->load->view('ajout_user', $data);
  }
}
public function update_user(){
  $this->form_validation->set_rules('name', 'Name', 'trim|required|alpha|xss_clean|htmlenties');
  $this->form_validation->set_rules('father_name', 'Father name', 'trim|required|alpha|xss_clean|htmlentities');
}
if($this->form_validation->run() && $this->input->post('confirmer')){
   $this->userManager->modifier_user($this->input->post('id_user'),
                                                                        $this->input->post('name'),
                                                        $this->input->post('father_name'));
$this->load->view('validation');
}else{
$data['img_captcha'] = $this->_create_captcha();
$this->load->view('confirmation', $data);
}
}
this is my model:
Code:
class User_model extends CI_Model{

public function __construct(){
  parent::__construct();
}

protected $table = "user";

public function ajouter_user($id_user, $name, $father_name){
if($id_user == null AND $name == null AND $father_name == null){
return false;
}else{
$this->db->set('id_user', $id_user)
  ->set('name', $name)
  ->set('father_name', $father_name);
         return $this->db->insert($this->table);
}
public function modifier_user($id_user, $name, $father_name){
if($id_user == null AND $name == null AND $father_name == null){
return false;
}else{
$this->db->set('name', $name)
  ->set('father_name', $father_name)
         ->where('id_user', $id_user);
return $this->db->update($this->table);
}
}
}

PS: sorry for my bad english (i'm french)




Theme © iAndrew 2016 - Forum software by © MyBB