PHP Codeigniter Controller Signup php code kese kare Php Simple trick se ish blog post main app ko best php code in codeigniter main sikhne ko milega
Start Codigniter controller php code
/* -----------------------------------------------------------------------
Signup page view
----------------------------------------------------------------------*/
public function signup_c()
{
$this->data['redata'] = array(
'first_name' => $this->input->post('firstName'),
'last_name' => $this->input->post('lastName'),
'username' => $this->input->post('username'),
'password' => $this->input->post('password'),
'email' => $this->input->post('email'),
'gender' => $this->input->post('gender'),
'dob' => $this->input->post('dob'),
'phone_number' =>$this->input->post('phoneNumber')
);
$this->form_validation->set_rules('firstName','firstName','trim|required');
$this->form_validation->set_rules('lastName','lastName','trim|required');
$this->form_validation>set_rules('username','username','trim|required|is_unique[user_data.username]');
$this->form_validation->set_rules('password','password',
'trim|required|regex_match[/^((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})$/]');
$this->form_validation->set_rules('email','Email','trim|required|is_unique[user_data.email]');
$this->form_validation->set_rules('phoneNumber','phoneNumber','trim|required|regex_match[/^[0-9]{10}$/]');
if ($this->form_validation->run() == true) {
$fname = $this->input->post('firstName');
$lname = $this->input->post('lastName');
$uname = $this->input->post('username');
$pass = $this->input->post('password');
$email = $this->input->post('email');
$gender = $this->input->post('gender');
$dob = $this->input->post('dob');
$phoneNumber = $this->input->post('phoneNumber');
$file = "";
// image upload
$config['upload_path'] = './assets/uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('img_Src3')) {
$error = array('error' => $this->upload->display_errors());
} else {
$data = array('upload_data' => $this->upload->data());
$file = $data['upload_data']['file_name'];
}
$insert_user = array(
'first_name' => $fname,
'last_name' => $lname,
'username' => $uname,
'password' => $pass,
'email' => $email,
'gender' => $gender,
'dob' => $dob,
'phone_number' => $phoneNumber,
'img_src3' => $file,
'created_date' => date('y/m/d'),
'role' => 'ROLE_USER'
);
$insert_id = $this->User_model->adddata($insert_user);
// echo "last insert id = ".$insert_id;
// start welcome email
// $this->email->from('info@cinopix.com', 'Cinopix.com');
// $this->email->to($email);
// $this->email->subject('Welcome New Registration');
// $this->email->message(' Thank You for Registration...');
// $this->email->send();
// end welcome email
$this->session->set_flashdata('user_saved', 'User has been saved');
$this->load->view('inc/header');
$this->load->view('inc/nav');
$this->load->view('inc/signup', $this->data);
$this->load->view('inc/footer');
} else {
$this->load->view('inc/header');
$this->load->view('inc/nav');
$this->load->view('inc/signup', $this->data);
$this->load->view('inc/footer');
}
}