Welcome Guest, Not a member yet? Register   Sign In
Inserting user data problem
#1

[eluser]Skoobi[/eluser]
Hi im in the process of building a registration app for my site and the main thing i want it to do is check that the data is inserted into database then return true or false. For some reason im struggling with this.

Heres what im trying to do:

Signup form
>Sends the name, email, password to controller named (members/register)
>The members/register function checks the form validation and returns true or false for the form input.
>else if true i want it to add the data to the database but return true or false
> if it returns true then it will send a confirmation email with and activation code and redirects to signin form.

Controller:
Code:
// -----------------------------------------------------------------------------
// Signup Page
//------------------------------------------------------------------------------

public function signup()
{
  $this->header();
  $this->load->view('members/account/signup_view');
  $this->footer();
}

// Register the user and send activation email
//------------------------------------------------------------------------------

function register()
{  
  $this->settings();
  $this->load->library('email');
  $this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean');
  $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean|is_unique[customers.email]');
  $this->form_validation->set_rules('password', 'Password', 'required|trim|xss_clean|min_length[6]');
  $this->form_validation->set_rules('confirm_password', 'Confirm Password', 'required|trim|xss_clean|min_length[6]|matches[password]');
  $this->form_validation->set_message('email', 'Email address is already registered.');
  $this->form_validation->set_error_delimiters('  <span class="text text-danger"><small>','</small></span>');

  if ($this->form_validation->run() == FALSE)
  {
   $this->header();
   $this->load->view('members/account/signup_view');
   $this->footer();
  }
  elseif ($this->form_validation->run() == TRUE)
  {
   $query = $this->auth_model->register();
  
   if($query == TRUE)
   {
    // Configure the email prefs
    $config['mailtype'] = 'text';
    $config['newline'] = "\r\n";
    $this->email->initialize($config);

    $this->settings();
    $site_email = $this->config->item('site_email'); // Site Email Address
    $site_name = $this->config->item('site_name'); // Site Email Address

    // Send verification email to user
    $from = $site_email;
    $app_name = $site_name;
    $subject = "Registration Confirmation for " . $name;
    $message = "Thank you for registering at " . base_url() . ". To continue please click the link below to activate your account...\r\n\r\n";
    $message .= base_url('members/account_activation/' . $activation_code);
    $message .= "\r\n\r\n Thank you\r\nAdmin";

    $this->email->to($email);
    $this->email->from($from, $app_name);
    $this->email->subject($subject);
    $this->email->message($message);  
    $this->email->send();

    // Save to Database and redirect
    $this->auth_model->register();
    $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">Almost there!!! Please check your email for your activation link and follow the instructions.</div>');
    redirect('members/signin', 'refresh');

    if ($this->config->item('notify_admin') == TRUE) // Set in Settings/config)
    {
    // Notify admin
     $name = $this->input->post('name');
    
     $this->settings();
     $site_email = $this->config->item('site_email'); // Site Email Address
     $site_name = $this->config->item('site_name'); // Site Email Address

     $subject = "New Registration - " . $name;
     $message = "A new registration has been made";

     $this->email->to($site_email);
     $this->email->from($from, $site_name);
     $this->email->subject($subject);
     $this->email->message($message);  
     $this->email->send();
    }
    elseif($this->config->item('notify_admin') == FALSE)
    {
     // Do nothing
    }
   }else{
    $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">Theres an error.</div>');
    redirect('members/signup', 'refresh');
   }
  
  }
}

Model:
Code:
//------------------------------------------------------------------------------------
// register user
//------------------------------------------------------------------------------------

function register()
{
  $this->load->helper('string');
  
  $name = $this->input->post('name');
  $email = $this->input->post('email');
  $sha_password = sha1($this->input->post('password'));
  $activation_code = $this->input->post('activation_code');
  
  $data = array(
   'name'     => $name,
   'email'    => $email,
   'password'    => $sha_password,
   'activation_code'  => $activation_code,
   'status'   => 0,    
      'created'    => Date('Y-m-d H:i:s'),
   );

  $query = $this->db->insert('customers', $data);

  if ($query->affected_rows() > 0)
  {
   return TRUE;
  }
  else
  {
   return FALSE;
  }
  
}

Any help or pointers will be greatly recieved

Chris
#2

[eluser]CroNiX[/eluser]
Which part are you struggling with? What doesn't work specifically?




Theme © iAndrew 2016 - Forum software by © MyBB